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

Re: Alias expansion inconsistency in $(command substitutions) with IGNORE_CLOSE_BRACES



On Sun, 16 Apr 2017 17:07:09 +0100
Martijn Dekker <martijn@xxxxxxxx> 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



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