zsh-workers
 help / color / mirror / code / Atom feed
* Alias expansion inconsistency in $(command substitutions) with IGNORE_CLOSE_BRACES
@ 2017-04-16 16:07 Martijn Dekker
  2017-04-21 19:58 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Martijn Dekker @ 2017-04-16 16:07 UTC (permalink / raw)
  To: zsh-workers

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"
zsh: parse error near `)'
zsh: parse error near `var=$({ OPEN echo hi...'

This inconsistency seems to have been introduced around zsh 5.2; it's
not present in zsh 5.1.1 and earlier.

Thanks,

- M.

In case anyone wonders about an actual use case for aliases like these,
it's the var/setlocal module of modernish, my cross platform POSIX shell
library:
https://github.com/modernish/modernish#user-content-use-varsetlocal
This basically brings the functionality of zsh anonymous functions to
plain POSIX shells. Of course this would be redundant on scripts written
for zsh, but it would be nice if cross-shell scripts run consistently.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Alias expansion inconsistency in $(command substitutions) with IGNORE_CLOSE_BRACES
  2017-04-16 16:07 Alias expansion inconsistency in $(command substitutions) with IGNORE_CLOSE_BRACES Martijn Dekker
@ 2017-04-21 19:58 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2017-04-21 19:58 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-21 20:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-16 16:07 Alias expansion inconsistency in $(command substitutions) with IGNORE_CLOSE_BRACES Martijn Dekker
2017-04-21 19:58 ` Peter Stephenson

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).