diff --git a/examples/methods.ion b/examples/methods.ion index 26dd757f594ee073692ee15087748038bcc01cfa..158489d9ded4d061302064961236f52200b6bf2e 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 cddebc27ecbd89d887fffb613fc6fa13b3910f8a..f60f29e72bea01e4a1403169e2f4b9aece321f08 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 6bc66bc3c5c8b67879e8ca3b03c4910031424784..38b67f12632ed713ade7209124aa4e0ba0dc46fc 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 dc863fddec9b923d6ab74ab38dae04654688d917..73d0371384d884f3f490a10671a508b7294cbc8e 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 7b16eec6cb10ebfe65c91b36615dab60547dabcf..86e1aedf8f98e72b1a7a711f51d043a4bfd3863e 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