mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +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" |
|
"noembed" | "noframes" | "plaintext" |
|
||||||
"noscript" if elem.deref().namespace == namespace::HTML
|
"noscript" if elem.deref().namespace == namespace::HTML
|
||||||
=> html.push_str(text.deref().characterdata.data),
|
=> 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(attr.deref().name);
|
||||||
};
|
};
|
||||||
html.push_str("=\"");
|
html.push_str("=\"");
|
||||||
html.push_str(escape(attr.deref().value, true));
|
escape(attr.deref().value, true, html);
|
||||||
html.push_char('"');
|
html.push_char('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
fn escape(string: &str, attr_mode: bool) -> ~str {
|
fn escape(string: &str, attr_mode: bool, html: &mut StrBuf) {
|
||||||
let replaced = string.replace("&", "&").replace("\xA0", " ");
|
for c in string.chars() {
|
||||||
match attr_mode {
|
match c {
|
||||||
true => {
|
'&' => html.push_str("&"),
|
||||||
replaced.replace("\"", """)
|
'\xA0' => html.push_str(" "),
|
||||||
},
|
'"' if attr_mode => html.push_str("""),
|
||||||
false => {
|
'<' if !attr_mode => html.push_str("<"),
|
||||||
replaced.replace("<", "<").replace(">", ">")
|
'>' if !attr_mode => html.push_str(">"),
|
||||||
|
c => html.push_char(c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue