1
Fork 0

fix(ser): Fix serializing certain escaped characters

Fixes #7.
Closes #9.
This commit is contained in:
Lucas Schwiderski 2023-03-10 10:51:02 +01:00
parent 516ddd1b08
commit 702b2e4411
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8
3 changed files with 18 additions and 2 deletions

View file

@ -13,6 +13,7 @@
== Fixed == Fixed
- fix serializing strings containing `:` - fix serializing strings containing `:`
- fix serializing certain escaped characters
== [v0.2.4] - 2023-03-01 == [v0.2.4] - 2023-03-01

View file

@ -142,6 +142,14 @@ impl<'a> serde::ser::Serializer for &'a mut Serializer {
self.output.push('\\'); self.output.push('\\');
self.output.push('r'); self.output.push('r');
} }
'"' => {
self.output.push('\\');
self.output.push('"');
}
'\\' => {
self.output.push('\\');
self.output.push('\\');
}
c => { c => {
self.output.push(c); self.output.push(c);
} }

View file

@ -125,8 +125,15 @@ fn serialize_string() {
("foo\nbar", "\"foo\\nbar\""), ("foo\nbar", "\"foo\\nbar\""),
("foo\r\nbar", "\"foo\\r\\nbar\""), ("foo\r\nbar", "\"foo\\r\\nbar\""),
("foo\tbar", "\"foo\\tbar\""), ("foo\tbar", "\"foo\\tbar\""),
("foo/bar", "\"foo\\/bar\""), ("foo/bar", "foo/bar"),
("foo\\bar", "\"foo\\\\bar\""), ("foo\\bar", "\"foo\\\\bar\""),
// Regression test for #7.
("scripts/mods/test\\new", "\"scripts/mods/test\\\\new\""),
// Regression test for #8.
(
"+002023-03-03T16:42:33.944311860Z",
"\"+002023-03-03T16:42:33.944311860Z\"",
),
]; ];
for (value, expected) in tests { for (value, expected) in tests {
let expected = format!("value = {expected}\n"); let expected = format!("value = {expected}\n");
@ -152,7 +159,7 @@ fn serialize_char() {
('\t', "\"\\t\""), ('\t', "\"\\t\""),
('\r', "\"\\r\""), ('\r', "\"\\r\""),
('\\', "\"\\\\\""), ('\\', "\"\\\\\""),
('/', "\"\\/\""), ('/', "/"),
('\"', "\"\\\"\""), ('\"', "\"\\\"\""),
('\'', "\"'\""), ('\'', "\"'\""),
]; ];