Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] (z)-flag interrupts if $() in input



On Sun, 30 Oct 2016 11:04:55 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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.'



Messages sorted by: Reverse Date, Date, Thread, Author