summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2018-02-12 10:06:45 +0000
committerPeter Stephenson <pws@zsh.org>2018-02-12 10:06:45 +0000
commit47aa60950c488a49dc245659c126e3078bf499d0 (patch)
tree6429d9a55a7e17584fce5186de8a592f9729166b
parent2bf952b102bce70b879c00d2476a9a74eab5cfaf (diff)
downloadzsh-47aa60950c488a49dc245659c126e3078bf499d0.tar.gz
zsh-47aa60950c488a49dc245659c126e3078bf499d0.zip
42355: Fix use of backslashes on here doc input.
Handling of white space in particular was confusing and inconsistent with other shells.
-rw-r--r--ChangeLog6
-rw-r--r--Src/exec.c11
-rw-r--r--Test/A04redirect.ztst46
3 files changed, 58 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 4cc7820d2..522830fb4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-02-12 Peter Stephenson <p.stephenson@samsung.com>
+
+ * Marijn: 42355: Src/exec.c, Test/A04redirect.ztst:
+ Interpreation of backslash on here doc input was inconsistent
+ and confusing.
+
2018-02-12 Daniel Hahler <zsh@thequod.de>
* 42324: Completion/Unix/Command/_git: _git: handle mutually exclusive
diff --git a/Src/exec.c b/Src/exec.c
index c39680de7..e5c64555c 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4387,8 +4387,17 @@ gethere(char **strp, int typ)
bptr = buf + bsiz;
bsiz *= 2;
}
- if (lexstop || c == '\n')
+ if (lexstop)
break;
+ if (c == '\n') {
+ if (!qt && bptr > t && *(bptr - 1) == '\\') {
+ /* line continuation */
+ bptr--;
+ c = hgetc();
+ continue;
+ } else
+ break;
+ }
*bptr++ = c;
c = hgetc();
}
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index b8105cf6d..ef7ddb25a 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -114,7 +114,7 @@
heretest() {
print First line
cat <<' HERE'
- $foo$foo met celeste 'but with extra' "stuff to test quoting"
+ $foo$foo met celeste 'but with extra' "stuff to test quoting"\
HERE
print Last line
}
@@ -125,19 +125,57 @@
heretest
0:Re-evaluation of function output with here document, quoted
>First line
-> $foo$foo met celeste 'but with extra' "stuff to test quoting"
+> $foo$foo met celeste 'but with extra' "stuff to test quoting"\
>Last line
>First line
-> $foo$foo met celeste 'but with extra' "stuff to test quoting"
+> $foo$foo met celeste 'but with extra' "stuff to test quoting"\
>Last line
>First line
-> $foo$foo met celeste 'but with extra' "stuff to test quoting"
+> $foo$foo met celeste 'but with extra' "stuff to test quoting"\
>Last line
read -r line <<' HERE'
HERE
1:No input, not even newline, from empty here document.
+ heretest() {
+ print First line
+ cat <<-HERE
+ $foo\
+ $foo
+ some\
+ stuff
+ to\
+ test
+ tab\stripping
+ HERE
+ print Last line
+ }
+ heretest
+ eval "$(functions heretest)"
+ heretest
+ eval "$(functions heretest)"
+ heretest
+0:Line continuation in here-document with unquoted delimiter
+>First line
+>bar bar
+>some stuff
+>to test
+>tab\stripping
+>Last line
+>First line
+>bar bar
+>some stuff
+>to test
+>tab\stripping
+>Last line
+>First line
+>bar bar
+>some stuff
+>to test
+>tab\stripping
+>Last line
+
#
# exec tests: perform these in subshells so if they fail the
# shell won't exit.