fix(ser): Fix serializing certain escaped characters
Fixes #7. Closes #9.
This commit is contained in:
parent
516ddd1b08
commit
702b2e4411
3 changed files with 18 additions and 2 deletions
|
@ -13,6 +13,7 @@
|
|||
== Fixed
|
||||
|
||||
- fix serializing strings containing `:`
|
||||
- fix serializing certain escaped characters
|
||||
|
||||
== [v0.2.4] - 2023-03-01
|
||||
|
||||
|
|
|
@ -142,6 +142,14 @@ impl<'a> serde::ser::Serializer for &'a mut Serializer {
|
|||
self.output.push('\\');
|
||||
self.output.push('r');
|
||||
}
|
||||
'"' => {
|
||||
self.output.push('\\');
|
||||
self.output.push('"');
|
||||
}
|
||||
'\\' => {
|
||||
self.output.push('\\');
|
||||
self.output.push('\\');
|
||||
}
|
||||
c => {
|
||||
self.output.push(c);
|
||||
}
|
||||
|
|
|
@ -125,8 +125,15 @@ fn serialize_string() {
|
|||
("foo\nbar", "\"foo\\nbar\""),
|
||||
("foo\r\nbar", "\"foo\\r\\nbar\""),
|
||||
("foo\tbar", "\"foo\\tbar\""),
|
||||
("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 {
|
||||
let expected = format!("value = {expected}\n");
|
||||
|
@ -152,7 +159,7 @@ fn serialize_char() {
|
|||
('\t', "\"\\t\""),
|
||||
('\r', "\"\\r\""),
|
||||
('\\', "\"\\\\\""),
|
||||
('/', "\"\\/\""),
|
||||
('/', "/"),
|
||||
('\"', "\"\\\"\""),
|
||||
('\'', "\"'\""),
|
||||
];
|
||||
|
|
Loading…
Add table
Reference in a new issue