Skip to content

Commit 2532291

Browse files
author
Maciej Skrzypkowski
committed
New characters escaped in serialize_name
Added escape of NULL (U+0000) char and escape for characters in the range [\1-\1f] (U+0001 to U+001F) or U+007F according to https://drafts.csswg.org/cssom/#serialize-an-identifier Needed for proper CSS tests servo/servo#10685
1 parent 1950c75 commit 2532291

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/serializer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ fn serialize_name<W>(value: &str, dest: &mut W) -> fmt::Result where W:fmt::Writ
196196
let escaped = match b {
197197
b'0'...b'9' | b'A'...b'Z' | b'a'...b'z' | b'_' | b'-' => continue,
198198
_ if !b.is_ascii() => continue,
199-
b'\n' => Some("\\A "),
200-
b'\r' => Some("\\D "),
201-
b'\x0C' => Some("\\C "),
199+
b'\0' => Some("\u{FFFD}"),
202200
_ => None,
203201
};
204202
try!(dest.write_str(&value[chunk_start..i]));
205203
if let Some(escaped) = escaped {
206204
try!(dest.write_str(escaped));
205+
} else if (b >= b'\x01' && b <= b'\x1F') || b == b'\x7F' {
206+
try!(write!(dest, "\\{:x} ", b));
207207
} else {
208208
try!(write!(dest, "\\{}", b as char));
209209
}

0 commit comments

Comments
 (0)