From: Peter Stephenson <p.stephenson@samsung.com>
To: Martijn Dekker <martijn@inlv.org>, zsh-workers@zsh.org
Subject: Re: 'case' pattern matching bug with bracket expressions
Date: Thu, 14 May 2015 17:17:16 +0100 [thread overview]
Message-ID: <20150514171716.69cd99c9@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <5554C3A5.4030205@inlv.org>
On Thu, 14 May 2015 16:47:49 +0100
Martijn Dekker <martijn@inlv.org> wrote:
> What confounded me is that this applies even if the pattern is [$var] or
> even ["$var"], where $var is empty. This causes the bracket pattern to
> unexpectedly swallow anything that follows it if $var is empty. That
> seems very unexpected and undesirable to me, particularly since, as far
> as I know, zsh appears to be the only shell that chooses to handle it
> this way.
Sorry about the multiple emails...
I don't *think* the following patch makes anything worse, but notice
you're in any case on fairly soggy ground here, even in bash:
$ var=
$ [[ ']' = [$var]*[$var] ]] && echo matches
matches
and presumably Chet would agree with me that's required by the
standard.
pws
diff --git a/Src/pattern.c b/Src/pattern.c
index 05dcb29..4e5e8a1 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -1405,7 +1405,16 @@ patcomppiece(int *flagp, int paren)
starter = patnode(P_ANYBUT);
} else
starter = patnode(P_ANYOF);
- if (*patparse == Outbrack) {
+ /*
+ * []...] means match a "]" or other included characters.
+ * However, to be a bit helpful and for compatibility
+ * with other shells, don't take it in that sense if
+ * there's no further active "]". That's still imperfect,
+ * but it's all we can do --- we're required to
+ * treat [$var]*[$var]with empty var as [ ... ]
+ * containing "]*[".
+ */
+ if (*patparse == Outbrack && strchr(patparse+1, Outbrack)) {
patparse++;
patadd(NULL, ']', 1, PA_NOALIGN);
}
next prev parent reply other threads:[~2015-05-14 16:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-14 13:14 Martijn Dekker
2015-05-14 13:50 ` [BUG] " Martijn Dekker
2015-05-14 14:42 ` Peter Stephenson
2015-05-14 15:47 ` Martijn Dekker
2015-05-14 15:55 ` Peter Stephenson
2015-05-14 17:30 ` Bart Schaefer
2015-05-15 0:05 ` Chet Ramey
2015-05-14 23:51 ` Chet Ramey
2015-05-15 8:38 ` Peter Stephenson
2015-05-15 20:48 ` Peter Stephenson
2015-05-15 21:48 ` Bart Schaefer
2015-05-14 16:17 ` Peter Stephenson [this message]
2015-05-14 17:07 ` Martijn Dekker
2015-05-14 17:43 ` Peter Stephenson
2015-05-15 0:09 ` Chet Ramey
2015-05-14 23:59 ` Chet Ramey
2015-05-14 21:23 ` Chet Ramey
2015-05-14 23:45 ` Chet Ramey
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=20150514171716.69cd99c9@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=martijn@inlv.org \
--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).