From: Martijn Dekker <martijn@inlv.org>
To: zsh-workers@zsh.org
Subject: Re: '<<-' here-documents oddity with line continuation
Date: Fri, 9 Feb 2018 19:19:52 +0100 [thread overview]
Message-ID: <54d294e7-bc09-0398-ae5d-8117d80fef36@inlv.org> (raw)
In-Reply-To: <abe0eef0-e1f8-081b-9af7-e089b91ecebe@inlv.org>
[-- Attachment #1: Type: text/plain, Size: 901 bytes --]
Op 09-02-18 om 17:07 schreef Martijn Dekker:
> Op 09-02-18 om 16:27 schreef Stephane Chazelas:
>> Note that there's also:
>>
>> cat << EOF
>> foo
>> E\
>> OF
>>
>> which zsh does differently from other shells (and that nobody
>> would ever do).
>
> IOW, all shells support line continuation within the terminating
> delimiter except zsh. Eesh.
>
> Somebody somewhere has probably done this. I'll see if I can rethink my
> patch to fix this as well.
Stéphane helped me realise my whole approach to the patch was wrong. Of
course line continuation should be handled within the loop that parses a
line in the first place, and not in between parsing individual lines. No
extra flag is needed at all.
Here's take two, which should fix all three issues. I also added a test
case, and slightly edited another test case to make sure line
continuation is not parsed if the delimiter is quoted.
- Martijn
[-- Attachment #2: heredoc.patch --]
[-- Type: text/plain, Size: 2209 bytes --]
diff --git a/Src/exec.c b/Src/exec.c
index c39680d..e5c6455 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 b8105cf..ef7ddb2 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.
next prev parent reply other threads:[~2018-02-09 18:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-03 17:39 Martijn Dekker
2018-02-09 7:01 ` Martijn Dekker
2018-02-09 7:58 ` Martijn Dekker
2018-02-09 9:24 ` Peter Stephenson
2018-02-09 15:27 ` Stephane Chazelas
2018-02-09 16:07 ` Martijn Dekker
2018-02-09 18:19 ` Martijn Dekker [this message]
2018-02-12 10:07 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54d294e7-bc09-0398-ae5d-8117d80fef36@inlv.org \
--to=martijn@inlv.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).