about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-04-28 10:20:35 +0100
committerPeter Stephenson <pws@zsh.org>2017-04-28 10:22:43 +0100
commited4e37e45c2f5761981cdc6027a5d6abc753176a (patch)
tree2395b7c4996c93021f2d306796c25b6ca66e0565
parentd7110d8f01cae8c8d51c7abd0255f533cd8b8623 (diff)
downloadzsh-ed4e37e45c2f5761981cdc6027a5d6abc753176a.tar.gz
zsh-ed4e37e45c2f5761981cdc6027a5d6abc753176a.tar.xz
zsh-ed4e37e45c2f5761981cdc6027a5d6abc753176a.zip
41020: Fix "command -p"; "-p" was incorrectly left in command arguments
Also add tests for known precommand modifier issues.
-rw-r--r--ChangeLog5
-rw-r--r--Src/exec.c9
-rw-r--r--Test/A01grammar.ztst12
3 files changed, 24 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 243957455..d434649bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-04-28  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* 41020: Src/exec.c, Test/A01grammar.ztst: "command -p" was
+	broken by 41008, also add more tests for precommand modifiers.
+
 2017-04-27  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* 41012: Src/builtin.c, Src/exec.c, Src/signals.c,
diff --git a/Src/exec.c b/Src/exec.c
index e0fc54445..9a75dd284 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2824,7 +2824,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
 		 * Otherwise, just leave marked as BINF_COMMAND
 		 * modifier with no additional action.
 		 */
-		LinkNode argnode, oldnode;
+		LinkNode argnode, oldnode, pnode = NULL;
 		char *argdata, *cmdopt;
 		int has_p = 0, has_vV = 0, has_other = 0;
 		argnode = firstnode(preargs);
@@ -2845,6 +2845,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
 			     * also traditional behaviour.
 			     */
 			    has_p = 1;
+			    pnode = argnode;
 			    break;
 			case 'v':
 			case 'V':
@@ -2882,6 +2883,12 @@ execcmd_exec(Estate state, Execcmd_params eparams,
 		} else if (has_p) {
 		    /* Use default path */
 		    use_defpath = 1;
+		    /*
+		     * We don't need this node as we're not treating
+		     * "command" as a builtin this time.
+		     */
+		    if (pnode)
+			uremnode(preargs, pnode);
 		}
 		/*
 		 * Else just any trailing
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 37311cea7..9625a15bc 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -116,9 +116,11 @@
 
   (\exec /bin/sh -c 'echo Test one'; print Not reached)
   ('exec' /bin/sh -c 'echo Test two'; print Not reached)
-0:exec with quotes
+  (\exec -c /bin/sh -c 'echo Test three'; print Not reached)
+0:precommand modifiers with quotes
 >Test one
 >Test two
+>Test three
 
   cat() { echo Function cat executed; }
   command cat && unfunction cat
@@ -126,6 +128,14 @@
 <External command cat executed
 >External command cat executed
 
+  (command -p echo this is output)
+  (\command -p echo this is more output)
+  ('command' -p echo this is yet more output)
+0: command -p without -v or -V
+>this is output
+>this is more output
+>this is yet more output
+
   command -pv cat
   command -pv echo
   command -p -V cat