Skip to content

Commit

Permalink
Fix overeager quoting constructs in Perl lexer (#1335)
Browse files Browse the repository at this point in the history
Perl allows for certain characters to be used as delimiters in quoting
constructs. The underscore was incorrectly being permitted to be used
as a delimiter. This fixes that bug.
  • Loading branch information
Brent Laabs authored and pyrmont committed Sep 26, 2019
1 parent 8fefabe commit 3e4da3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/perl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def self.detect?(text)
rule %r/(q|qq|qw|qr|qx)\(/, Str::Other, :rb_string
rule %r/(q|qq|qw|qr|qx)\[/, Str::Other, :sb_string
rule %r/(q|qq|qw|qr|qx)</, Str::Other, :lt_string
rule %r/(q|qq|qw|qr|qx)([^a-zA-Z0-9])(.|\n)*?\2/, Str::Other
rule %r/(q|qq|qw|qr|qx)(\W)(.|\n)*?\2/, Str::Other

rule %r/package\s+/, Keyword, :modulename
rule %r/sub\s+/, Keyword, :funcname
Expand Down
4 changes: 4 additions & 0 deletions spec/visual/samples/perl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ my $str2 = "This is a $string with plain interpolation."
my $cmd2 = `So is @this one.`
my $str3 = 'A boring $string.'

my @w = ( q!str4!, qw< str5 str6 >, qq(str7 $str1), qx`false`, qr/foo/ );
$a = qr/bar/i;
my %x = ( q_ThisString => "doesnt_overrun as if it were q-quoted" );

# from http://gist.github.com/485595
use strict;
use warnings;
Expand Down

0 comments on commit 3e4da3f

Please sign in to comment.