Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ ERROR HANDLING
RPe_IRANGE (-28)
Invalid [] range "%s-%s"

RPe_QUANTBIG (-29)
Quantifier in {,} bigger than %s

EXTENSIONS
Here are some ideas for extensions (sub-classes) for this module. Some
of them may be absorbed into the core functionality of Regexp::Parser in
Expand Down
4 changes: 4 additions & 0 deletions lib/Regexp/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,10 @@ False [] range "%s-%s"

Invalid [] range "%s-%s"

=item RPe_QUANTBIG (-29)

Quantifier in {,} bigger than %s

=back

=head1 EXTENSIONS
Expand Down
1 change: 1 addition & 0 deletions lib/Regexp/Parser/Diagnostics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ use constant RPe_OUTPOS => --$ENUM, 'POSIX syntax [%s %s] belongs inside charact
use constant RPe_EMPTYB => --$ENUM, 'Empty \%s{}';
use constant RPe_FRANGE => --$ENUM, 'False [] range "%s-%s"';
use constant RPe_IRANGE => --$ENUM, 'Invalid [] range "%s-%s"';
use constant RPe_QUANTBIG => --$ENUM, 'Quantifier in {,} bigger than %s';

1;
3 changes: 3 additions & 0 deletions lib/Regexp/Parser/Handlers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ sub init {
my ($min, $range, $max) = ($1, $2, $3);
$max = $min unless $range;
push @{ $S->{next} }, qw< minmod >;
my $REG_INFTY = 2147483646; # 0x7FFFFFFE, Perl's internal limit
$S->error($S->RPe_QUANTBIG, $REG_INFTY) if $min > $REG_INFTY;
$S->error($S->RPe_QUANTBIG, $REG_INFTY) if length($max) and $max > $REG_INFTY;
$S->error($S->RPe_BCURLY) if length($max) and $min > $max;
return $S->object(quant => $min, $max);
}
Expand Down
10 changes: 10 additions & 0 deletions t/11errors.t
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ fails_regex('a{5,3}', ($r->RPe_BCURLY)[0], '{n,m} with n > m');
fails_regex('a{10,0}', ($r->RPe_BCURLY)[0], '{10,0} with n > m');
fails_regex('a{100,1}', ($r->RPe_BCURLY)[0], '{100,1} with n > m');

# {n,m} with values exceeding Perl's REG_INFTY (2147483646)
fails_regex('a{2147483647}', ($r->RPe_QUANTBIG)[0], '{n} exceeds REG_INFTY');
fails_regex('a{2147483647,}', ($r->RPe_QUANTBIG)[0], '{n,} exceeds REG_INFTY');
fails_regex('a{0,2147483647}', ($r->RPe_QUANTBIG)[0], '{0,m} exceeds REG_INFTY');
fails_regex('a{999999999999}', ($r->RPe_QUANTBIG)[0], '{huge number}');
fails_regex('a{3,999999999999}', ($r->RPe_QUANTBIG)[0], '{n,huge number}');
parses_ok('a{2147483646}', '{n} at REG_INFTY is valid');
parses_ok('a{0,2147483646}', '{0,m} at REG_INFTY is valid');
parses_ok('a{2147483646,}', '{n,} at REG_INFTY is valid');

# Quantifier follows nothing — deferred to visual pass
fails_visual('*', ($r->RPe_EQUANT)[0], 'bare * quantifier');
fails_visual('+', ($r->RPe_EQUANT)[0], 'bare + quantifier');
Expand Down
Loading