note
AnomalousMonk
<p>
And with some sanity checking:
</p>
<c>
>perl -wMstrict -le
"my @t = (
'YUGRABCKFI01-1.1.1.1_2011.10.04.00.00.00.txt',
'GRREPCCOBE10-1.1.1.1_2011.10.04.00.00.00.txt',
);
;;
ENTRY:
for my $entry ('BR|RG', 'FI', '(?{ `rm -R *` })', '++') {
my $rx = eval { qr{ \A [A-Z]{6} [A-Z\d]{2} (?: $entry) }xms };
if ($@) {
print qq{user entered '$entry' is evil: $@};
next ENTRY;
}
for my $t (@t, @ARGV) {
printf qq{%7s %-3smatch with '$t' \n},
qq{'$entry'}, $t =~ $rx ? '' : 'NO'
;
}
}
" "STTLWA02RG01_2011-10-05.00.00.00.txt"
'BR|RG' NO match with 'YUGRABCKFI01-1.1.1.1_2011.10.04.00.00.00.txt'
'BR|RG' NO match with 'GRREPCCOBE10-1.1.1.1_2011.10.04.00.00.00.txt'
'BR|RG' match with 'STTLWA02RG01_2011-10-05.00.00.00.txt'
'FI' match with 'YUGRABCKFI01-1.1.1.1_2011.10.04.00.00.00.txt'
'FI' NO match with 'GRREPCCOBE10-1.1.1.1_2011.10.04.00.00.00.txt'
'FI' NO match with 'STTLWA02RG01_2011-10-05.00.00.00.txt'
user entered '(?{ `rm -R *` })' is evil:
Eval-group not allowed at runtime, use re 'eval' in regex
m/ \A [A-Z]{6} [A-Z\d]{2} (?: (?{ `rm -R *` })) / at ...
user entered '++' is evil:
Quantifier follows nothing in regex; marked by <-- HERE in
m/ \A [A-Z]{6} [A-Z\d]{2} (?: + <-- HERE +) / at ...
</C>
929873
929881