@@ -537,7 +537,11 @@ sub print_matches_in_resource {
537
537
while ( $contents =~ / $opt_regex /og ) {
538
538
my $match_start = $- [0];
539
539
my $match_end = $+ [0];
540
- next if $match_start == $match_end ;
540
+ next if $match_start == $match_end ; # continue to the next line
541
+ # if we match nothing, since
542
+ # some regexes allow this
543
+ # and would throw us into
544
+ # an infinite loop
541
545
542
546
pos ($contents ) = $prev_match_end ;
543
547
$prev_match_end = $match_end ;
@@ -641,7 +645,9 @@ sub print_line_with_options {
641
645
my $offset = 0; # additional offset for when we add stuff
642
646
my $previous_match_end = 0;
643
647
644
- last if $- [0] == $+ [0];
648
+ last if $- [0] == $+ [0]; # stop highlighting if we've hit an
649
+ # empty match, since continuing would
650
+ # result in an infinite loop
645
651
646
652
for ( my $i = 1; $i < @+; $i ++ ) {
647
653
my ( $match_start , $match_end ) = ( $- [$i ], $+ [$i ] );
@@ -672,7 +678,9 @@ sub print_line_with_options {
672
678
$matched = 1;
673
679
my ( $match_start , $match_end ) = ($- [0], $+ [0]);
674
680
next unless defined ($match_start );
675
- last if $match_start == $match_end ;
681
+ last if $match_start == $match_end ; # stop highlighting if we've hit an
682
+ # empty match, since continuing would
683
+ # result in an infinite loop
676
684
677
685
my $substring = substr ( $line , $match_start ,
678
686
$match_end - $match_start );
0 commit comments