diff options
author | Michael Sloan <mgsloan@gmail.com> | 2020-01-30 00:55:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-30 08:55:36 +0100 |
commit | bb675c5f56c6ddb5d450df53d2685f519dc8d78c (patch) | |
tree | dac7bf5544e05d91c49adb7239d4643d28559ba1 /src | |
parent | f60e3423426c7322533433f9d40e0f282a05d220 (diff) | |
download | milf-rs-bb675c5f56c6ddb5d450df53d2685f519dc8d78c.tar.gz milf-rs-bb675c5f56c6ddb5d450df53d2685f519dc8d78c.zip |
Fix roundtripping of \u001f and \u007f in toml string literals (#372)
Diffstat (limited to 'src')
-rw-r--r-- | src/ser.rs | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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), |