zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Cc: Yuya Amemiya <ghostrevery@gmail.com>
Subject: Re: z parameter expansion flag is broken?
Date: Sun, 10 Sep 2017 17:42:24 +0100	[thread overview]
Message-ID: <20170910174224.54ed65f6@ntlworld.com> (raw)
In-Reply-To: <20170909.041303.1592547893142420542.ghostrevery@gmail.com>

On Sat, 09 Sep 2017 04:13:03 +0900 (JST)
Yuya Amemiya <ghostrevery@gmail.com> wrote:
> Why does z parameter expansion flag remove leading '-' from result?
> 
> in zsh 5.4.1
> 
> ```
> $ echo ${(z):--a}
> a

That's a bug, but the only new feature is that it now additionally affects
"-" because that's tokenized.  The basic effect is old:

% zsh-5.3.1 -f
% setopt nonomatch
% echo ${(z):-foo*bar}
foobar

Because "-" doesn't usually need quoting, it's more noticeable than with
other metacharacters.

Untokenizing before passing to bufferwords() is the easy fix, and the
result can only be better because anything altered would previously
simply have been dumped by the effect noted by Bart.  However, I'm not
at all convinced bufferwords() needs to dump token characters in this
case --- bufferwords() is a hack that originated as a helper for
completion but is now more widely used.  A more elegant solution (not on
the cards) wouldn't use bufferwords() at all.

pws

diff --git a/Src/subst.c b/Src/subst.c
index 5b1bf89..5df2a8b 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3747,11 +3747,15 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 
 	if (isarr) {
 	    char **ap;
-	    for (ap = aval; *ap; ap++)
+	    for (ap = aval; *ap; ap++) {
+		untokenize(*ap);
 		list = bufferwords(list, *ap, NULL, shsplit);
+	    }
 	    isarr = 0;
-	} else
+	} else {
+	    untokenize(val);
 	    list = bufferwords(NULL, val, NULL, shsplit);
+	}
 
 	if (!list || !firstnode(list))
 	    val = dupstring("");
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 3c93990..8dbc1e8 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -2200,3 +2200,10 @@ F:behavior, see http://austingroupbugs.net/view.php?id=888
 >Option
 >Regular text
 >Option
+
+ (setopt nonomatch
+  print ${(z):-foo-bar*thingy?}
+ )
+0:(z) splitting with remaining tokens
+>foo-bar*thingy?
+ 


      parent reply	other threads:[~2017-09-10 16:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-08 19:13 Yuya Amemiya
2017-09-09 16:53 ` Bart Schaefer
2017-09-09 22:45   ` Bart Schaefer
2017-09-11 10:44     ` Peter Stephenson
2017-09-10 16:42 ` 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=20170910174224.54ed65f6@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=ghostrevery@gmail.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).