about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-03-09 09:52:23 +0000
committerPeter Stephenson <pws@zsh.org>2017-03-09 09:52:23 +0000
commit64559abc1fdd375e5672a03c29c20a7a49259e29 (patch)
tree0c9d370d9a39be28471f25a951b880fa52e2849c
parentc93f29b52d4dc6725841671cafd4a9ea845a9598 (diff)
downloadzsh-64559abc1fdd375e5672a03c29c20a7a49259e29.tar.gz
zsh-64559abc1fdd375e5672a03c29c20a7a49259e29.tar.xz
zsh-64559abc1fdd375e5672a03c29c20a7a49259e29.zip
40796: MAGIC_EQUAL_SUBST not needed with parsed assignment.
If typeset family builtins are recognised as keywords then the value
is handled as a separate expansion and we don't need the old
magic behaviour, even if the option is set.
-rw-r--r--ChangeLog5
-rw-r--r--Src/exec.c25
2 files changed, 25 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index ec784d0ce..46184fa35 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-03-09  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* 40796: Src/exec.c: We don't want magic '=' expansion if we are
+	already parsing a separate variable name and value.
+
 2017-03-08  Barton E. Schaefer  <schaefer@zsh.org>
 
 	* 40799: Src/params.c: fix $- expansion partly broken by 40760
diff --git a/Src/exec.c b/Src/exec.c
index 8b3224652..137130e31 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2658,7 +2658,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
     char *text;
     int save[10];
     int fil, dfil, is_cursh, do_exec = 0, redir_err = 0, i;
-    int nullexec = 0, assign = 0, forked = 0;
+    int nullexec = 0, magic_assign = 0, forked = 0;
     int is_shfunc = 0, is_builtin = 0, is_exec = 0, use_defpath = 0;
     /* Various flags to the command. */
     int cflags = 0, orig_cflags = 0, checked = 0, oautocont = -1;
@@ -2761,7 +2761,8 @@ execcmd_exec(Estate state, Execcmd_params eparams,
 		/* autoload the builtin if necessary */
 		if (!(hn = resolvebuiltin(cmdarg, hn)))
 		    return;
-		assign = (hn->flags & BINF_MAGICEQUALS);
+		if (type != WC_TYPESET)
+		    magic_assign = (hn->flags & BINF_MAGICEQUALS);
 		break;
 	    }
 	    checked = 0;
@@ -2929,8 +2930,22 @@ execcmd_exec(Estate state, Execcmd_params eparams,
     if (noerrexit == 2 && !is_shfunc)
 	noerrexit = 0;
 
-    /* Do prefork substitutions */
-    esprefork = (assign || isset(MAGICEQUALSUBST)) ? PREFORK_TYPESET : 0;
+    /* Do prefork substitutions.
+     *
+     * Decide if we need "magic" handling of ~'s etc. in
+     * assignment-like arguments.
+     * - If magic_assign is set, we are using a builtin of the
+     *   tyepset family, but did not recognise this as a keyword,
+     *   so need guess-o-matic behaviour.
+     * - Otherwise, if we did recognise the keyword, we never need
+     *   guess-o-matic behaviour as the argument was properly parsed
+     *   as such.
+     * - Otherwise, use the behaviour specified by the MAGIC_EQUAL_SUBST
+     *   option.
+     */
+    esprefork = (magic_assign ||
+		 (isset(MAGICEQUALSUBST) && type != WC_TYPESET)) ?
+		 PREFORK_TYPESET : 0;
     if (args && eparams->htok)
 	prefork(args, esprefork, NULL);
 
@@ -3710,7 +3725,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
 		     * Save if it's got "command" in front or it's
 		     * not a magic-equals assignment.
 		     */
-		    if ((cflags & (BINF_COMMAND|BINF_ASSIGN)) || !assign)
+		    if ((cflags & (BINF_COMMAND|BINF_ASSIGN)) || !magic_assign)
 			do_save = 1;
 		}
 		if (do_save && varspc)