- and returns the corresponding regular expression (or "undef" if the
- source is invalid) according to standard Unix wildcard rules. It
- successively escapes all regexp special characters that doesn't hold any
- meaning for wildcards, turns jokers into their regexp equivalents, and
- changes bracketed blocks into alternations. If brackets are unbalanced,
- it will try to substitute as many of them as possible, and then escape
- the remaining "{" and "}".
+ and returns the corresponding regular expression according to standard
+ Unix wildcard rules. It successively escapes all unprotected regexp
+ special characters that doesn't hold any meaning for wildcards, turns
+ jokers into their regexp equivalents, and changes bracketed blocks into
+ "(?:|)" alternations. If brackets are unbalanced, it will try to
+ substitute as many of them as possible, and then escape the remaining
+ "{" and "}". Commas outside of any bracket-delimited block will also be
+ escaped.
+
+ # This is a valid brackets expression which is correctly handled.
+ print 'ok' if wc2re_unix('{a{b,c}d,e}') eq '(?:a(?:b|c)d|e)';
+
+ Unbalanced bracket expressions can always be rescued, but it may change
+ completely its meaning. For example :
+
+ # The first comma is replaced, and the remaining brackets and comma are
+ # escaped.
+ print 'ok' if wc2re_unix('{a\\{b,c}d,e}') eq '(?:a\\{b|c)d\\,e\\}';
+
+ # All the brackets and commas are escaped.
+ print 'ok' if wc2re_unix('{a{b,c\\}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';