Skip to content

Commit f523b41

Browse files
Fix Unicode C1 control character escaping
1 parent 026f49b commit f523b41

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

json/src/ser.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,12 @@ pub fn escape_bytes<W>(wr: &mut W, bytes: &[u8]) -> Result<()>
494494
try!(wr.write_all(b"\""));
495495

496496
let mut start = 0;
497-
let mut last_byte_was_c2 = false;
497+
let mut last_byte = 0u8;
498498

499499
for (i, byte) in bytes.iter().enumerate() {
500+
let last_byte_was_c2 = last_byte == b'\xC2';
501+
last_byte = *byte;
502+
500503
let escaped = match *byte {
501504
b'"' => b"\\\"",
502505
b'\\' => b"\\\\",
@@ -527,10 +530,6 @@ pub fn escape_bytes<W>(wr: &mut W, bytes: &[u8]) -> Result<()>
527530

528531
continue;
529532
},
530-
b'\xC2' => {
531-
last_byte_was_c2 = true;
532-
continue;
533-
},
534533
_ => { continue; }
535534
};
536535

0 commit comments

Comments
 (0)