Skip to content

Commit 2b9cd8d

Browse files
authored
fix: Escape '<' and '>' when serializing attribute values (#697)
There was an update to the HTML Standard (whatwg/html@e21bd3b) to mandate escaping of '<' and '>' in attribute values. This commit updates the attribute serialization logic to comply with the current specification.
1 parent fa69d1a commit 2b9cd8d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

html5ever/src/serialize/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl<Wr: Write> HtmlSerializer<Wr> {
107107
'&' => self.writer.write_all(b"&amp;"),
108108
'\u{00A0}' => self.writer.write_all(b"&nbsp;"),
109109
'"' if attr_mode => self.writer.write_all(b"&quot;"),
110-
'<' if !attr_mode => self.writer.write_all(b"&lt;"),
111-
'>' if !attr_mode => self.writer.write_all(b"&gt;"),
110+
'<' => self.writer.write_all(b"&lt;"),
111+
'>' => self.writer.write_all(b"&gt;"),
112112
c => self.writer.write_fmt(format_args!("{c}")),
113113
}?;
114114
}

rcdom/tests/html-serializer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ test!(
140140
r#"<p><i>Hello!</i></p><i>, World!</i>"#
141141
);
142142

143-
test!(attr_literal, r#"<base foo="<'>">"#);
143+
test!(
144+
attr_literal,
145+
r#"<base foo="<'>">"#,
146+
r#"<base foo="&lt;'&gt;">"#
147+
);
144148
test!(attr_escape_amp, r#"<base foo="&amp;">"#);
145149
test!(
146150
attr_escape_amp_2,

0 commit comments

Comments
 (0)