From a92266db70f481f52f3e14e857e1ead300b1f473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Wed, 20 Mar 2019 00:00:00 +0000 Subject: Fix parsing of repeated delimiters inside multi-line strings The previous implementation of `read_string`, when looking for delimiters ending the multi-line string and failing to find exactly three in succession, always put a single delimiter back. This is incorrect when exactly two delimiters are present. Put back the correct number of delimiters depending on how many have been already consumed from input. The issue could be triggered only with `Owned` representation of `MaybeString`, since otherwise `push` operation is no-op. --- src/tokens.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tokens.rs b/src/tokens.rs index 064c804..6413ce1 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -336,11 +336,14 @@ impl<'a> Tokenizer<'a> { } Some((i, ch)) if ch == delim => { if multiline { - for _ in 0..2 { - if !self.eatc(delim) { - val.push(delim); - continue 'outer; - } + if !self.eatc(delim) { + val.push(delim); + continue 'outer; + } + if !self.eatc(delim) { + val.push(delim); + val.push(delim); + continue 'outer; } } return Ok(String { @@ -630,6 +633,7 @@ mod tests { t(r#""\"a""#, "\"a", false); t("\"\"\"\na\"\"\"", "a", true); t("\"\"\"\n\"\"\"", "", true); + t(r#""""a\"""b""""#, "a\"\"\"b", true); err(r#""\a"#, Error::InvalidEscape(2, 'a')); err("\"\\\n", Error::InvalidEscape(2, '\n')); err("\"\\\r\n", Error::InvalidEscape(2, '\n')); -- cgit v1.2.3