Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix character escaping in Perl lexer #1549

Merged
Merged
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
12 changes: 10 additions & 2 deletions lib/rouge/lexers/perl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,24 @@ def self.detect?(text)
end

state :sq do
rule %r/\\[']/, Str::Escape
rule %r/\\[\\']/, Str::Escape
rule %r/[^\\']+/, Str::Single
rule %r/'/, Punctuation, :pop!
rule %r/\\/, Str::Single
end

state :dq do
mixin :string_intp
rule %r/\\[\\tnr"]/, Str::Escape
rule %r/\\[\\tnrabefluLUE"$@]/, Str::Escape
rule %r/\\0\d{2}/, Str::Escape
rule %r/\\o\{\d+\}/, Str::Escape
rule %r/\\x\h{2}/, Str::Escape
rule %r/\\x\{\h+\}/, Str::Escape
rule %r/\\c./, Str::Escape
rule %r/\\N\{[^\}]+\}/, Str::Escape
rule %r/[^\\"]+?/, Str::Double
rule %r/"/, Punctuation, :pop!
rule %r/\\/, Str::Escape
end

state :bq do
Expand Down
8 changes: 8 additions & 0 deletions spec/visual/samples/perl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ $s =~ y/[]|/()&/; # "backward" compatible


# quoted strings
my $a = 'foo';
my $a = 'foo\'s bar';
my $a = 'foo\bar';
my $a = 'foo\\bar';
my $a = "foo";
my $a = "foo \" bar";
my $a = "foo\bar";
my $a = "foo \057 \x7f \x{263a} \cC \N{GREEK SMALL LETTER SIGMA} bar";
my $a = "invalid escape \w";

print "a: ";
print $a, " - ";
Expand Down