Merge pull request #294 from tmiasko/ml-delim

Fix parsing of repeated delimiters inside multi-line strings
This commit is contained in:
Alex Crichton 2019-03-20 14:07:50 -05:00 committed by GitHub
commit 19ac1ea19c

View file

@ -336,11 +336,14 @@ impl<'a> Tokenizer<'a> {
} }
Some((i, ch)) if ch == delim => { Some((i, ch)) if ch == delim => {
if multiline { if multiline {
for _ in 0..2 { if !self.eatc(delim) {
if !self.eatc(delim) { val.push(delim);
val.push(delim); continue 'outer;
continue 'outer; }
} if !self.eatc(delim) {
val.push(delim);
val.push(delim);
continue 'outer;
} }
} }
return Ok(String { return Ok(String {
@ -630,6 +633,7 @@ mod tests {
t(r#""\"a""#, "\"a", false); t(r#""\"a""#, "\"a", false);
t("\"\"\"\na\"\"\"", "a", true); t("\"\"\"\na\"\"\"", "a", true);
t("\"\"\"\n\"\"\"", "", true); t("\"\"\"\n\"\"\"", "", true);
t(r#""""a\"""b""""#, "a\"\"\"b", true);
err(r#""\a"#, Error::InvalidEscape(2, 'a')); err(r#""\a"#, Error::InvalidEscape(2, 'a'));
err("\"\\\n", Error::InvalidEscape(2, '\n')); err("\"\\\n", Error::InvalidEscape(2, '\n'));
err("\"\\\r\n", Error::InvalidEscape(2, '\n')); err("\"\\\r\n", Error::InvalidEscape(2, '\n'));