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

enh(perl) fix false-positive variable match at end of string (plus test) #3943

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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Core Grammars:

- enh(perl) fix false-positive variable match at end of string [Josh Goebel][]
- fix(cpp) not all kinds of number literals are highlighted correctly [Lê Duy Quang][]
- fix(css) fix overly greedy pseudo class matching [Bradley Mackey][]
- enh(arcade) updated to ArcGIS Arcade version 1.24 [Kristian Ekenes][]
Expand Down Expand Up @@ -43,6 +44,7 @@ Themes:
[Robloxian Demo]: https://github.com/RobloxianDemo
[Paul Tsnobiladzé]: https://github.com/tsnobip
[Jonah Jeleniewski]: https://github.com/cirras
[Josh Goebel]: https://github.com/joshgoebel
[CY Fung]: https://github.com/cyfung1031
[Vitaly Barilko]: https://github.com/Diversus23

Expand Down
4 changes: 2 additions & 2 deletions src/languages/perl.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ export default function(hljs) {
variants: [
{ begin: /\$\d/ },
{ begin: regex.concat(
/[$%@](\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
/[$%@](?!")(\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
// negative look-ahead tries to avoid matching patterns that are not
// Perl at all like $ident$, @ident@, etc.
`(?![A-Za-z])(?![@$%])`
)
},
{
// Only $= is a special Perl variable and one can't declare @= or %=.
begin: /[$%@][^\s\w{=]|\$=/,
begin: /[$%@](?!")[^\s\w{=]|\$=/,
relevance: 0
}
],
Expand Down
4 changes: 4 additions & 0 deletions test/markup/perl/default.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<span class="hljs-comment"># GH-117</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$g</span> = <span class="hljs-keyword">glob</span>(<span class="hljs-string">&quot;/usr/bin/*&quot;</span>);

<span class="hljs-comment"># GH-3934</span>
<span class="hljs-keyword">print</span> <span class="hljs-string">&quot;@&quot;</span>;
<span class="hljs-keyword">print</span>;

<span class="hljs-keyword">return</span> <span class="hljs-variable">$o</span>;
}

Expand Down
4 changes: 4 additions & 0 deletions test/markup/perl/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ sub load
# GH-117
my $g = glob("/usr/bin/*");

# GH-3934
print "@";
print;

return $o;
}

Expand Down
Loading