Merge pull request #8 from huonw/fixit
Disambiguate "" empty strings from multiline strings properly.
This commit is contained in:
commit
76cf3d1d3e
|
@ -265,11 +265,16 @@ impl<'a> Parser<'a> {
|
||||||
let mut multiline = false;
|
let mut multiline = false;
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
|
|
||||||
// detect multiline literals
|
// detect multiline literals, but be careful about empty ""
|
||||||
|
// strings
|
||||||
if self.eat('"') {
|
if self.eat('"') {
|
||||||
multiline = true;
|
if self.eat('"') {
|
||||||
if !self.expect('"') { return None }
|
multiline = true;
|
||||||
self.eat('\n');
|
self.eat('\n');
|
||||||
|
} else {
|
||||||
|
// empty
|
||||||
|
return Some(String(ret))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|
|
@ -122,6 +122,9 @@ test!(long_float,
|
||||||
test!(long_integer,
|
test!(long_integer,
|
||||||
include_str!("valid/long-integer.toml"),
|
include_str!("valid/long-integer.toml"),
|
||||||
include_str!("valid/long-integer.json"))
|
include_str!("valid/long-integer.json"))
|
||||||
|
test!(string_empty,
|
||||||
|
include_str!("valid/string-empty.toml"),
|
||||||
|
include_str!("valid/string-empty.json"))
|
||||||
test!(string_escapes,
|
test!(string_escapes,
|
||||||
include_str!("valid/string-escapes.toml"),
|
include_str!("valid/string-escapes.toml"),
|
||||||
include_str!("valid/string-escapes.json"))
|
include_str!("valid/string-escapes.json"))
|
||||||
|
|
6
src/test/valid/string-empty.json
Normal file
6
src/test/valid/string-empty.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"answer": {
|
||||||
|
"type": "string",
|
||||||
|
"value": ""
|
||||||
|
}
|
||||||
|
}
|
1
src/test/valid/string-empty.toml
Normal file
1
src/test/valid/string-empty.toml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
answer = ""
|
Loading…
Reference in a new issue