From a6f8f1dcb96fb9c6a87a63ea2c8d4f38b1702d3e Mon Sep 17 00:00:00 2001 From: Juho Peltonen <juhopel@gmail.com> Date: Sun, 31 Dec 2017 12:05:40 +0200 Subject: [PATCH] Fix for double quote parsing --- examples/methods.ion | 3 ++- examples/methods.out | 1 + examples/strings.ion | 4 ++++ examples/strings.out | 4 ++++ src/lib/parser/shell_expand/words/mod.rs | 10 ++++++++-- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/methods.ion b/examples/methods.ion index 26dd757f..158489d9 100644 --- a/examples/methods.ion +++ b/examples/methods.ion @@ -30,7 +30,8 @@ echo $repeat("one ", 5) echo $join([one two three], "\n") echo $join([one two three], "\t") -echo $join([one two three], "\\n") +echo $join([one two three], '\\n') +echo $join([one two three], "\\\\n") echo $replace($join([one two three], "\n"), "\n" "\t") let a = "applesauce" let pos = $find(a, "s") diff --git a/examples/methods.out b/examples/methods.out index cddebc27..f60f29e7 100644 --- a/examples/methods.out +++ b/examples/methods.out @@ -62,6 +62,7 @@ two three one two three one\ntwo\nthree +one\ntwo\nthree one two three apple sauce diff --git a/examples/strings.ion b/examples/strings.ion index 6bc66bc3..38b67f12 100644 --- a/examples/strings.ion +++ b/examples/strings.ion @@ -2,3 +2,7 @@ echo hello?world echo hello*world echo hello^world echo hello%world +echo "\$hello" +echo "\\" +echo "\n" +echo "\"" diff --git a/examples/strings.out b/examples/strings.out index dc863fdd..73d03713 100644 --- a/examples/strings.out +++ b/examples/strings.out @@ -2,3 +2,7 @@ hello?world hello*world hello^world hello%world +$hello +\ +\n +" diff --git a/src/lib/parser/shell_expand/words/mod.rs b/src/lib/parser/shell_expand/words/mod.rs index 7b16eec6..86e1aedf 100644 --- a/src/lib/parser/shell_expand/words/mod.rs +++ b/src/lib/parser/shell_expand/words/mod.rs @@ -749,9 +749,15 @@ impl<'a, E: Expander + 'a> Iterator for WordIterator<'a, E> { while let Some(character) = iterator.next() { match character { _ if self.flags.contains(Flags::BACKSL) => self.flags ^= Flags::BACKSL, - b'\\' => { + b'\\' if !self.flags.contains(Flags::SQUOTE) => { self.flags ^= Flags::BACKSL; - let end = if self.flags.intersects(Flags::DQUOTE | Flags::SQUOTE) { + + let include_backsl = self.flags.contains(Flags::DQUOTE) + && iterator.clone().next().map_or(false, |nextch| { + nextch != b'$' && nextch != b'\\' && nextch != b'"' + }); + + let end = if include_backsl { self.read + 1 } else { self.read -- GitLab