LanX has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Edge case in Text::Glob
by salva (Canon) on Mar 01, 2022 at 16:19 UTC | |
by LanX (Saint) on Mar 01, 2022 at 16:37 UTC | |
by Fletch (Bishop) on Mar 01, 2022 at 17:45 UTC | |
by LanX (Saint) on Mar 02, 2022 at 15:42 UTC | |
by Fletch (Bishop) on Mar 02, 2022 at 16:29 UTC | |
|