zsh-workers
 help / color / mirror / code / Atom feed
* 'case' pattern matching bug with bracket expressions
@ 2015-05-14 13:14 Martijn Dekker
  2015-05-14 13:50 ` [BUG] " Martijn Dekker
  2015-05-14 14:42 ` Peter Stephenson
  0 siblings, 2 replies; 18+ messages in thread
From: Martijn Dekker @ 2015-05-14 13:14 UTC (permalink / raw)
  To: zsh-workers

While writing a cross-platform shell library I've come across a bug in
the way zsh (in POSIX mode) matches patterns in 'case' statements that
are at variance with other POSIX shells.

Normally, zsh considers an empty bracket expression [] a bad pattern
while other shells ([d]ash, bash, ksh) consider it a negative:

case abc in ( [] ) echo yes ;; ( * ) echo no ;; esac

Expected output: no
Got output: zsh: bad pattern: []

This is inconvenient if you want to pass such a bracket expression in a
parameter or variable, e.g. ["$param"]. If the parameter or variable is
empty, a 'bad pattern: []' error is produced.

I'm not sure whether the above is a bug or a variance in behaviour
permitted by POSIX, though of course as a writer of cross-platform shell
programs I'd prefer it if zsh acted like the majority.

However, I'm quite sure the following is a serious bug.

The same thing does NOT produce an error, but a false positive (!), if
an extra non-matching pattern with | is added:

case abc in ( [] | *[!a-z]*) echo yes ;; ( * ) echo no ;; esac

Expected output: no
Got output: yes

The above needs to be tested in a non-interactive shell (i.e. a script)
due to the "!". Other shells I've tested (bash, dash, ksh, pdksh, mksh)
behave as expected.

I confirmed the bug in zsh 4.3.11, zsh 5.0.2 and zsh 5.0.7-dev-2.

Thanks,

- Martijn


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-05-15 21:48 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-14 13:14 'case' pattern matching bug with bracket expressions 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
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

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).