zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] quoting within bracket patterns has no effect
@ 2016-01-18  4:23 Martijn Dekker
  2016-01-18 17:24 ` Peter Stephenson
  0 siblings, 1 reply; 17+ messages in thread
From: Martijn Dekker @ 2016-01-18  4:23 UTC (permalink / raw)
  To: zsh-workers, ast-developers

Quotes should disable the special meaning of characters in glob
patterns[*]. So this:

case b in
( ['a-c'] ) echo 'false match' ;;
( [a-c] )   echo 'correct match' ;;
esac

should output "correct match". But on zsh and AT&T ksh93 (and only
those), it outputs "false match". Meaning, quoting the characters within
the bracket pattern does not disable the special meaning of '-' in the
bracket pattern.

This hinders a realistic use case: the ability to pass a series of
arbitrary characters in a variable for use within a bracket pattern.
Quoting the variable does not have any effect; if the series contains a
'-', the result is unexpected. For example:

mychars='abs$ad-f3ra'  # arbitrary series of characters containing '-'
somevar=qezm           # this contains none of the characters above
case $somevar in
( *["$mychars"]* )  echo "$somevar contains one of $mychars" ;;
esac

produces a false positive on zsh and ksh93.

A workaround is to make sure the '-', if any, is always last in the
string of characters to match against.

The same thing also affects glob patterns in other contexts, e.g.
removing characters using parameter substitution.

Other shells, at least bash, (d)ash variants, pdksh, mksh and yash, all
act like POSIX says they should, according to my tests.	

Thanks,

- Martijn

[*] "If any character (ordinary, shell special, or pattern special) is
quoted, that pattern shall match the character itself."
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13_01


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

end of thread, other threads:[~2016-01-27  3:04 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-18  4:23 [BUG] quoting within bracket patterns has no effect Martijn Dekker
2016-01-18 17:24 ` Peter Stephenson
2016-01-19 15:57   ` Jun T.
2016-01-19 17:35     ` Peter Stephenson
2016-01-19 18:54       ` Bart Schaefer
2016-01-20 10:48       ` Jun T.
2016-01-20 11:04         ` Peter Stephenson
2016-01-19 16:03   ` Peter Stephenson
2016-01-19 16:25     ` Mikael Magnusson
2016-01-19 16:34       ` Peter Stephenson
2016-01-19 18:41     ` Bart Schaefer
2016-01-23  0:17   ` Martijn Dekker
2016-01-23  1:49     ` Bart Schaefer
2016-01-26  4:03       ` Martijn Dekker
2016-01-26  4:48         ` Bart Schaefer
2016-01-26 14:07           ` Martijn Dekker
2016-01-27  3:05             ` Bart Schaefer

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