aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2019-03-20 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2019-03-20 17:58:14 +0100
commita92266db70f481f52f3e14e857e1ead300b1f473 (patch)
tree3b1da285129b52ba02fb4995b442768e9cb76ea0 /src
parentdbdcc9ccc4233b4a7b3a1ce42d49fb863f1c903a (diff)
downloadmilf-rs-a92266db70f481f52f3e14e857e1ead300b1f473.tar.gz
milf-rs-a92266db70f481f52f3e14e857e1ead300b1f473.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/tokens.rs14
1 files 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'));