We are using web-forms where users can configure filters for various lists of strings.
I've convinced my colleagues to use globs instead of far to powerful regexes.
For that we are using Text::Glob which is internally translating Perl's glob syntax to a regex.
But I stumbled over an incompatibility while testing with character classes provided with [...] because an unpaired [ is not masked.
Demo:
DB<84> x <[*> 0 '[KSR_3.pl' DB<85> $re = glob_to_regex( '[*' ) Unmatched [ in regex; marked by <-- HERE in m/^(?=[^\.])[ <-- HERE (?: +(?!\/).)*$/ at c:/Strawberry/perl/vendor/lib/Text/Glob.pm line 18. DB<86> x $re_str = glob_to_regex_string( '[*' ) 0 '(?=[^\\.])[(?:(?!\\/).)*' DB<87>
Point is that fileglob is automatically using the unpaired [ as a literal character, while Text::Glob is entering it as unescaped regex-meta which is causing a syntax error.
I'm not sure how to handle this best, an eval { glob_to_regex('[*') } will catch this particular input, but maybe not other broken code...
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Edge case in Text::Glob by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |