Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 'case' pattern matching bug with bracket expressions



On Thu, 14 May 2015 18:07:39 +0100
Martijn Dekker <martijn@xxxxxxxx> wrote:
> However, the more insidious case that bit me:
> 
> case abc in ( [] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac
> empty=''
> case abc in ( ["$empty"] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac
> 
> still produces a false positive even with the patch.

This is hairy because you're relying on whitespace performing word
splitting in a case where you don't need whitespace according to the
grammar anyway, i.e. if you have the valid expression

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

it can only be parsed the way zsh parses it --- you'll find bash does
the same.

I'll have a look at changing the way we handle whitespace in
bracketed expressions in POSIX mode (POSIX_STRINGS option?  That's
about the closest I can see and underworked at the moment).

The above still needs some work, though, since we don't currently word
split case statements.  I think that probably is required by the
standard since it specifies word (though not word list) handling,
i.e. implying the same as command line words but with an additional "|"
token between words.  That's probably going to have to wait till after
5.0.8.

pws



Messages sorted by: Reverse Date, Date, Thread, Author