zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: [BUG] (z)-flag interrupts if $() in input
Date: Thu, 03 Nov 2016 10:23:34 +0000	[thread overview]
Message-ID: <20161103102334.173d37e5@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <161030110455.ZM14677@torch.brasslantern.com>

On Sun, 30 Oct 2016 11:04:55 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> This solves the specific example but doesn't solve the general problem;
> if there is a parse error inside $(...) then ${(z)...} fails.
> 
> torch% a='x $() y'
> torch% print -rl -- ${(z)a}
> x
> $()
> y
> torch% a='x $(|||) y'
> torch% print -rl -- ${(z)a}
> x
> $(||

This fixes it up in the usual way, i.e. read to the end of the string
but don't attempt to parse further.  It's easy since we're still in the
mode where the command substitution is being copied to the token on
input, so just carry on doing that until the end of the string.

pws

diff --git a/Src/lex.c b/Src/lex.c
index e0935bf..8896128 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -2138,8 +2138,17 @@ skipcomm(void)
     lexflags &= ~LEXFLAGS_ZLE;
     dbparens = 0;	/* restored by zcontext_restore_partial() */
 
-    if (!parse_event(OUTPAR) || tok != OUTPAR)
-	lexstop = 1;
+    if (!parse_event(OUTPAR) || tok != OUTPAR) {
+	if (strin) {
+	    /*
+	     * Get the rest of the string raw since we don't
+	     * know where this token ends.
+	     */
+	    while (!lexstop)
+		(void)ingetc();
+	} else
+	    lexstop = 1;
+    }
      /* Outpar lexical token gets added in caller if present */
 
     /*
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 7623051..97c8ba3 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -631,6 +631,14 @@
 >;
 >(( echo 42 
 
+  # From parse error on it's not possible to split.
+  # Just check we get the complete string.
+  foo='echo $(|||) bar'
+  print -rl ${(z)foo}
+0:$($(z)} with parse error in command substitution.
+>echo
+>$(|||) bar
+
   psvar=(dog)
   setopt promptsubst
   foo='It shouldn'\''t $(happen) to a %1v.'


  parent reply	other threads:[~2016-11-03 10:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-30  6:33 Sebastian Gniazdowski
2016-10-30 15:25 ` Daniel Shahaf
2016-10-30 17:09   ` Peter Stephenson
2016-10-30 18:04     ` Bart Schaefer
2016-10-30 20:14       ` Bart Schaefer
2016-11-03 10:23       ` Peter Stephenson [this message]
2016-10-30 17:55   ` Bart Schaefer

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=20161103102334.173d37e5@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --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).