aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-07-18 09:55:32 -0400
committerAlex Crichton <alex@alexcrichton.com>2014-07-18 09:55:32 -0400
commit76cf3d1d3ef0fb21ade21d313d8b67b65ed7e8ac (patch)
tree2ccbf27ac04539985419897bf0225267c22f2541
parent05f8c0bc41a10f1e98e420f8d02d778541d13d48 (diff)
parente756f56b62053a34aa26a00e28dbe4ce29cd9125 (diff)
downloadmilf-rs-76cf3d1d3ef0fb21ade21d313d8b67b65ed7e8ac.tar.gz
milf-rs-76cf3d1d3ef0fb21ade21d313d8b67b65ed7e8ac.zip
Merge pull request #8 from huonw/fixit
Disambiguate "" empty strings from multiline strings properly.
-rw-r--r--src/parser.rs13
-rw-r--r--src/test/valid.rs3
-rw-r--r--src/test/valid/string-empty.json6
-rw-r--r--src/test/valid/string-empty.toml1
4 files changed, 19 insertions, 4 deletions
diff --git a/src/parser.rs b/src/parser.rs
index ec9adf9..27edd2f 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -265,11 +265,16 @@ impl<'a> Parser<'a> {
let mut multiline = false;
let mut ret = String::new();
- // detect multiline literals
+ // detect multiline literals, but be careful about empty ""
+ // strings
if self.eat('"') {
- multiline = true;
- if !self.expect('"') { return None }
- self.eat('\n');
+ if self.eat('"') {
+ multiline = true;
+ self.eat('\n');
+ } else {
+ // empty
+ return Some(String(ret))
+ }
}
loop {
diff --git a/src/test/valid.rs b/src/test/valid.rs
index 9a812d5..1bcfeb2 100644
--- a/src/test/valid.rs
+++ b/src/test/valid.rs
@@ -122,6 +122,9 @@ test!(long_float,
test!(long_integer,
include_str!("valid/long-integer.toml"),
include_str!("valid/long-integer.json"))
+test!(string_empty,
+ include_str!("valid/string-empty.toml"),
+ include_str!("valid/string-empty.json"))
test!(string_escapes,
include_str!("valid/string-escapes.toml"),
include_str!("valid/string-escapes.json"))
diff --git a/src/test/valid/string-empty.json b/src/test/valid/string-empty.json
new file mode 100644
index 0000000..6c26d69
--- /dev/null
+++ b/src/test/valid/string-empty.json
@@ -0,0 +1,6 @@
+{
+ "answer": {
+ "type": "string",
+ "value": ""
+ }
+}
diff --git a/src/test/valid/string-empty.toml b/src/test/valid/string-empty.toml
new file mode 100644
index 0000000..e37e681
--- /dev/null
+++ b/src/test/valid/string-empty.toml
@@ -0,0 +1 @@
+answer = ""