Merge pull request #263 from Deewiant/final-quote-fix
Avoid panic on pretty string ending in single quote
This commit is contained in:
commit
ae5595396f
|
@ -585,6 +585,10 @@ impl<'a> Serializer<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if can_be_pretty && found_singles > 0 && value.ends_with('\'') {
|
||||||
|
// We cannot escape the ending quote so we must use """
|
||||||
|
can_be_pretty = false;
|
||||||
|
}
|
||||||
if !can_be_pretty {
|
if !can_be_pretty {
|
||||||
debug_assert!(ty != Type::OnelineTripple);
|
debug_assert!(ty != Type::OnelineTripple);
|
||||||
return Repr::Std(ty);
|
return Repr::Std(ty);
|
||||||
|
|
|
@ -250,3 +250,7 @@ test!(table_array_nest_no_keys,
|
||||||
test!(dotted_keys,
|
test!(dotted_keys,
|
||||||
include_str!("valid/dotted-keys.toml"),
|
include_str!("valid/dotted-keys.toml"),
|
||||||
include_str!("valid/dotted-keys.json"));
|
include_str!("valid/dotted-keys.json"));
|
||||||
|
|
||||||
|
test!(quote_surrounded_value,
|
||||||
|
include_str!("valid/quote-surrounded-value.toml"),
|
||||||
|
include_str!("valid/quote-surrounded-value.json"));
|
||||||
|
|
10
test-suite/tests/valid/quote-surrounded-value.json
Normal file
10
test-suite/tests/valid/quote-surrounded-value.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"double": {
|
||||||
|
"type": "string",
|
||||||
|
"value": "\"double quotes here\""
|
||||||
|
},
|
||||||
|
"single": {
|
||||||
|
"type": "string",
|
||||||
|
"value": "'single quotes here'"
|
||||||
|
}
|
||||||
|
}
|
2
test-suite/tests/valid/quote-surrounded-value.toml
Normal file
2
test-suite/tests/valid/quote-surrounded-value.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
double = '"double quotes here"'
|
||||||
|
single = "'single quotes here'"
|
Loading…
Reference in a new issue