Closed ArtBlnd closed 3 years ago
Do you have a unit test that demonstrates the problem more clearly?
1. Create empty document.
2. Create script element
3. Create text node and append to script element
4. Serialize document to string.
Then you can see script in the element is xml escaped.
In this case, the script text in the element should NOT xml escaped by that html5ever's implementation. it checks parent element is script.
Can you share the actual code that demonstrates this, including the serializing code?
If you need unit test for reproduce. I'll write new one for you. our test is highly depended on our infrastructure. so I need to write new one.
#[cfg(test)]
mod tests {
use kuchiki::traits::*;
use kuchiki::{parse_html, Attribute, ExpandedName, NodeRef};
use markup5ever::*;
#[test]
fn test() {
fn create_element(name: &str, att: Option<Vec<(&str, &str)>>) -> NodeRef {
let att = if let Some(att) = att {
att.iter()
.map(|(k, v)| {
(
ExpandedName::new(ns!(), LocalName::from(*k)),
Attribute {
prefix: None,
value: v.to_string(),
},
)
})
.collect()
} else {
Vec::new()
};
let local_name = if name == "script" {
local_name!("script")
} else {
LocalName::from(name)
};
NodeRef::new_element(QualName::new(None, ns!(), local_name), att)
}
let document = parse_html().one("");
let head = document.select_first("head").unwrap();
let script = create_element("script", None);
script.append(NodeRef::new_text("some_script>another_script"));
head.as_node().append(script);
assert_eq!(document.to_string(), "<html><head><script>some_script>another_script</script></head><body></body></html>");
}
}
Expect result is but <html><head><script>some_script>another_script</script></head><body></body></html>
<html><head><script>some_script>another_script</script></head><body></body></html>
I believe the problem is that you're using ns!()
, instead of ns!(html)
when creating the element.
Seems it has same issue with ns!(html)
Ah nevermind. fixed!
Seems newly generated Text node in Script node is generating script to Xml escaped string.
}