Fix roundtripping of \u001f and \u007f in toml string literals (#372)
This commit is contained in:
parent
f022d042dd
commit
cd96581730
|
@ -569,8 +569,9 @@ impl<'a> Serializer<'a> {
|
|||
match ch {
|
||||
'\t' => {}
|
||||
'\n' => ty = Type::NewlineTripple,
|
||||
// note that the following are invalid: \b \f \r
|
||||
c if c < '\u{1f}' => can_be_pretty = false, // Invalid control character
|
||||
// Escape codes are needed if any ascii control
|
||||
// characters are present, including \b \f \r.
|
||||
c if c <= '\u{1f}' || c == '\u{7f}' => can_be_pretty = false,
|
||||
_ => {}
|
||||
}
|
||||
out.push(ch);
|
||||
|
@ -646,7 +647,7 @@ impl<'a> Serializer<'a> {
|
|||
'\u{d}' => self.dst.push_str("\\r"),
|
||||
'\u{22}' => self.dst.push_str("\\\""),
|
||||
'\u{5c}' => self.dst.push_str("\\\\"),
|
||||
c if c < '\u{1f}' => {
|
||||
c if c <= '\u{1f}' || c == '\u{7f}' => {
|
||||
write!(self.dst, "\\u{:04X}", ch as u32).map_err(ser::Error::custom)?;
|
||||
}
|
||||
ch => self.dst.push(ch),
|
||||
|
|
|
@ -46,5 +46,13 @@
|
|||
"notunicode4": {
|
||||
"type": "string",
|
||||
"value": "This string does not have a unicode \\\u0075 escape."
|
||||
},
|
||||
"delete": {
|
||||
"type": "string",
|
||||
"value": "This string has a \u007f delete control code."
|
||||
},
|
||||
"unitseparator": {
|
||||
"type": "string",
|
||||
"value": "This string has a \u001f unit separator control code."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,3 +10,5 @@ notunicode1 = "This string does not have a unicode \\u escape."
|
|||
notunicode2 = "This string does not have a unicode \u005Cu escape."
|
||||
notunicode3 = "This string does not have a unicode \\u0075 escape."
|
||||
notunicode4 = "This string does not have a unicode \\\u0075 escape."
|
||||
delete = "This string has a \u007F delete control code."
|
||||
unitseparator = "This string has a \u001F unit separator control code."
|
||||
|
|
Loading…
Reference in a new issue