zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: Alias expansion inconsistency in $(command substitutions) with IGNORE_CLOSE_BRACES
Date: Fri, 21 Apr 2017 20:58:15 +0100	[thread overview]
Message-ID: <20170421205815.11935aed@ntlworld.com> (raw)
In-Reply-To: <131b162a-b1f8-998c-e5ca-6a161dfef16f@inlv.org>

On Sun, 16 Apr 2017 17:07:09 +0100
Martijn Dekker <martijn@inlv.org> wrote:
> If either the IGNORE_CLOSE_BRACES or IGNORE_BRACES option is active,
> there is an inconsistency in alias expansion within command
> substitutions, specifically those of the form $(command).
> 
> Given:
> 
> % set -o ignoreclosebraces
> % alias OPEN='{' CLOSE='};'
> 
> These work fine:
> 
> % { OPEN echo hi; CLOSE }
> hi
> % var=`{ OPEN echo hi; CLOSE }` && echo "$var"
> hi
> 
> But this does not:
> 
> % var=$({ OPEN echo hi; CLOSE }) && echo "$var"

We are too cavalier in our initial parsing to determine where the
command substitution ends.

pws

diff --git a/Src/lex.c b/Src/lex.c
index 59e9d14..b2d9b3f 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -2060,9 +2060,7 @@ skipcomm(void)
     int new_lexstop, new_lex_add_raw;
     int save_infor = infor;
     struct lexbufstate new_lexbuf;
-    int noalias = noaliases;
 
-    noaliases = 1;
     infor = 0;
     cmdpush(CS_CMDSUBST);
     SETPARBEGIN
@@ -2189,7 +2187,6 @@ skipcomm(void)
 	SETPAREND
     cmdpop();
     infor = save_infor;
-    noaliases = noalias;
 
     return lexstop;
 #endif
diff --git a/Test/D08cmdsubst.ztst b/Test/D08cmdsubst.ztst
index 3625373..4e0759e 100644
--- a/Test/D08cmdsubst.ztst
+++ b/Test/D08cmdsubst.ztst
@@ -167,3 +167,13 @@
   empty=$() && print "'$empty'"
 0:Empty $() is a valid assignment
 >''
+
+  (
+    setopt ignoreclosebraces
+    alias OPEN='{' CLOSE='};'
+    eval '{ OPEN print hi; CLOSE }
+    var=$({ OPEN print bye; CLOSE}) && print $var'
+  )
+0:Alias expansion needed in parsing substituions
+>hi
+>bye


      reply	other threads:[~2017-04-21 20:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-16 16:07 Martijn Dekker
2017-04-21 19:58 ` Peter Stephenson [this message]

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=20170421205815.11935aed@ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).