Skip to content

Commit 185b35d

Browse files
committed
Add escape to write_str
1 parent 0caaba1 commit 185b35d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/serializer.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,17 @@ impl<'a, W> fmt::Write for CssStringWriter<'a, W> where W: fmt::Write {
250250
fn write_str(&mut self, s: &str) -> fmt::Result {
251251
let mut chunk_start = 0;
252252
for (i, b) in s.bytes().enumerate() {
253+
let string;
253254
let escaped = match b {
254255
b'"' => "\\\"",
255256
b'\\' => "\\\\",
256257
b'\n' => "\\A ",
257258
b'\r' => "\\D ",
258-
b'\x0C' => "\\C ",
259+
b'\0' => "\u{FFFD}",
260+
x if (x >= b'\x01' && x <= b'\x1F') || x == b'\x7F' => {
261+
string = format!("\\{:x} ", x);
262+
&string
263+
},
259264
_ => continue,
260265
};
261266
try!(self.inner.write_str(&s[chunk_start..i]));

0 commit comments

Comments
 (0)