Allow delimiter quotes at the end of multiline strings (#393)

TOML allows (unlike many other formats) up to 2
additonal quotes that are part of the string:

basic = """2 extra quotes -->"""""
literal = '''here too ''''

Changed in TOML v1.0.0-rc.1

See also #392
This commit is contained in:
pyfisch 2020-05-28 17:39:55 +02:00 committed by GitHub
parent b84615a24c
commit af05f537d8
4 changed files with 32 additions and 1 deletions

View file

@ -334,7 +334,7 @@ impl<'a> Tokenizer<'a> {
return Err(Error::NewlineInString(i)); return Err(Error::NewlineInString(i));
} }
} }
Some((i, ch)) if ch == delim => { Some((mut i, ch)) if ch == delim => {
if multiline { if multiline {
if !self.eatc(delim) { if !self.eatc(delim) {
val.push(delim); val.push(delim);
@ -345,6 +345,14 @@ impl<'a> Tokenizer<'a> {
val.push(delim); val.push(delim);
continue 'outer; continue 'outer;
} }
if self.eatc(delim) {
val.push(delim);
i += 1;
}
if self.eatc(delim) {
val.push(delim);
i += 1;
}
} }
return Ok(String { return Ok(String {
src: &self.input[start..self.current()], src: &self.input[start..self.current()],

View file

@ -389,3 +389,9 @@ test!(
include_str!("valid/float-exponent.toml"), include_str!("valid/float-exponent.toml"),
include_str!("valid/float-exponent.json") include_str!("valid/float-exponent.json")
); );
test!(
string_delim_end,
include_str!("valid/string-delim-end.toml"),
include_str!("valid/string-delim-end.json")
);

View file

@ -0,0 +1,14 @@
{
"str1": {
"type": "string",
"value": "\"This,\" she said, \"is just a pointless statement.\""
},
"str2": {
"type": "string",
"value": "foo''bar''"
},
"str3": {
"type": "string",
"value": "\"\""
}
}

View file

@ -0,0 +1,3 @@
str1 = """"This," she said, "is just a pointless statement.""""
str2 = '''foo''bar'''''
str3 = """"""""