mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Rewrite escape() in htmlserializer to push onto a StrBuf.
This commit is contained in:
parent
d1ca380482
commit
ce45afac0c
1 changed files with 12 additions and 11 deletions
|
@ -81,10 +81,10 @@ fn serialize_text(text: &JSRef<Text>, html: &mut StrBuf) {
|
|||
"noembed" | "noframes" | "plaintext" |
|
||||
"noscript" if elem.deref().namespace == namespace::HTML
|
||||
=> html.push_str(text.deref().characterdata.data),
|
||||
_ => html.push_str(escape(text.deref().characterdata.data, false))
|
||||
_ => escape(text.deref().characterdata.data, false, html)
|
||||
}
|
||||
}
|
||||
_ => html.push_str(escape(text.deref().characterdata.data, false))
|
||||
_ => escape(text.deref().characterdata.data, false, html)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,18 +151,19 @@ fn serialize_attr(attr: &JSRef<Attr>, html: &mut StrBuf) {
|
|||
html.push_str(attr.deref().name);
|
||||
};
|
||||
html.push_str("=\"");
|
||||
html.push_str(escape(attr.deref().value, true));
|
||||
escape(attr.deref().value, true, html);
|
||||
html.push_char('"');
|
||||
}
|
||||
|
||||
fn escape(string: &str, attr_mode: bool) -> ~str {
|
||||
let replaced = string.replace("&", "&").replace("\xA0", " ");
|
||||
match attr_mode {
|
||||
true => {
|
||||
replaced.replace("\"", """)
|
||||
},
|
||||
false => {
|
||||
replaced.replace("<", "<").replace(">", ">")
|
||||
fn escape(string: &str, attr_mode: bool, html: &mut StrBuf) {
|
||||
for c in string.chars() {
|
||||
match c {
|
||||
'&' => html.push_str("&"),
|
||||
'\xA0' => html.push_str(" "),
|
||||
'"' if attr_mode => html.push_str("""),
|
||||
'<' if !attr_mode => html.push_str("<"),
|
||||
'>' if !attr_mode => html.push_str(">"),
|
||||
c => html.push_char(c),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue