zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org, zsh-workers@zsh.org
Subject: Re: z parameter expansion flag is broken?
Date: Sat, 9 Sep 2017 09:53:52 -0700	[thread overview]
Message-ID: <170909095352.ZM8398@torch.brasslantern.com> (raw)
In-Reply-To: <20170909.041303.1592547893142420542.ghostrevery@gmail.com>

On Sep 9,  4:13am, Yuya Amemiya wrote:
}
} Why does z parameter expansion flag remove leading '-' from result?

Hrm.

In the (z) case, "-" has been tokenized as DASH when bufferwords() is
called.  This eventually comes down to ingetc() while reading the next
lexical word from the input buffer.  At line 202 there is

202                 if (itok(lastc = STOUC(*inbufptr++)))
203                     continue;

Because itok(DASH) is true, we discard it and continue around the loop.

That code in ingetc() is as old as the shell itself, so I have to assume
that there's a good reason to discard token characters during lexing,
and the problem is upstream with the recently-introduced code that
more aggressively tokenizes hyphens ... though I don't understand why
other tokens haven't similarly been adversely affected (or maybe I just
haven't found how to get another token embedded in the string).

In any case this is a really serious bug; it's not just leading "-" that
get removed:

torch% print -r -- ${(z):--a -b -c d-e-f}
a b c def


  reply	other threads:[~2017-09-09 16:52 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 [this message]
2017-09-09 22:45   ` Bart Schaefer
2017-09-11 10:44     ` Peter Stephenson
2017-09-10 16:42 ` Peter Stephenson

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=170909095352.ZM8398@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).