aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Niemenmaa <matti.niemenmaa+git@iki.fi>2018-10-01 11:58:57 +0300
committerMatti Niemenmaa <matti.niemenmaa+git@iki.fi>2018-10-01 11:58:57 +0300
commit2059589f5420bed3d490822fc9560db3c3a21515 (patch)
tree019d9a7a18b1512d099e8a8b704caad1b3c97b1f
parentf998fbe360b4ea37f27793a55831e988415b4b6d (diff)
downloadmilf-rs-2059589f5420bed3d490822fc9560db3c3a21515.tar.gz
milf-rs-2059589f5420bed3d490822fc9560db3c3a21515.zip
Avoid panic on pretty string ending in single quote
Fixes #262.
-rw-r--r--src/ser.rs4
-rw-r--r--test-suite/tests/valid.rs4
-rw-r--r--test-suite/tests/valid/quote-surrounded-value.json10
-rw-r--r--test-suite/tests/valid/quote-surrounded-value.toml2
4 files changed, 20 insertions, 0 deletions
diff --git a/src/ser.rs b/src/ser.rs
index 9d989db..9f36f59 100644
--- a/src/ser.rs
+++ b/src/ser.rs
@@ -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 {
debug_assert!(ty != Type::OnelineTripple);
return Repr::Std(ty);
diff --git a/test-suite/tests/valid.rs b/test-suite/tests/valid.rs
index d032ba5..7c1691c 100644
--- a/test-suite/tests/valid.rs
+++ b/test-suite/tests/valid.rs
@@ -250,3 +250,7 @@ test!(table_array_nest_no_keys,
test!(dotted_keys,
include_str!("valid/dotted-keys.toml"),
include_str!("valid/dotted-keys.json"));
+
+test!(quote_surrounded_value,
+ include_str!("valid/quote-surrounded-value.toml"),
+ include_str!("valid/quote-surrounded-value.json"));
diff --git a/test-suite/tests/valid/quote-surrounded-value.json b/test-suite/tests/valid/quote-surrounded-value.json
new file mode 100644
index 0000000..84495cf
--- /dev/null
+++ b/test-suite/tests/valid/quote-surrounded-value.json
@@ -0,0 +1,10 @@
+{
+ "double": {
+ "type": "string",
+ "value": "\"double quotes here\""
+ },
+ "single": {
+ "type": "string",
+ "value": "'single quotes here'"
+ }
+}
diff --git a/test-suite/tests/valid/quote-surrounded-value.toml b/test-suite/tests/valid/quote-surrounded-value.toml
new file mode 100644
index 0000000..dc8697e
--- /dev/null
+++ b/test-suite/tests/valid/quote-surrounded-value.toml
@@ -0,0 +1,2 @@
+double = '"double quotes here"'
+single = "'single quotes here'"