Skip to content

fix(bash): Comments false positives #3918

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

Merged
merged 1 commit into from
Nov 3, 2023
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 @@ -5,6 +5,7 @@ Core Grammars:
- fix(css) fix overly greedy pseudo class matching [Bradley Mackey][]
- enh(arcade) updated to ArcGIS Arcade version 1.24 [Kristian Ekenes][]
- fix(yaml) fix for yaml with keys having brackets highlighted incorrectly [Aneesh Kulkarni][]
- fix(bash) fix # within token being detected as the start of a comment [Felix Uhl][]

Developer Tool:

Expand All @@ -14,6 +15,7 @@ Developer Tool:
[Kristian Ekenes]: https://github.com/ekenes
[Aneesh Kulkarni]: https://github.com/aneesh98
[Bruno Meneguele]: https://github.com/bmeneg
[Felix Uhl]: https://github.com/iFreilicht


## Version 11.9.0
Expand Down
14 changes: 13 additions & 1 deletion src/languages/bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export default function(hljs) {
end: /\)/,
contains: [ hljs.BACKSLASH_ESCAPE ]
};
const COMMENT = hljs.inherit(
hljs.COMMENT(),
{
match: [
/(^|\s)/,
/#.*$/
],
scope: {
2: 'comment'
}
}
);
const HERE_DOC = {
begin: /<<-?\s*(?=\w+)/,
starts: { contains: [
Expand Down Expand Up @@ -376,7 +388,7 @@ export default function(hljs) {
hljs.SHEBANG(), // to catch unknown shells but still highlight the shebang
FUNCTION,
ARITHMETIC,
hljs.HASH_COMMENT_MODE,
COMMENT,
HERE_DOC,
PATH_MODE,
QUOTE_STRING,
Expand Down
3 changes: 3 additions & 0 deletions test/markup/bash/not-comments.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="hljs-built_in">echo</span> asdf#qwert yuiop

<span class="hljs-built_in">echo</span> asdf <span class="hljs-comment">#qwert yuiop</span>
3 changes: 3 additions & 0 deletions test/markup/bash/not-comments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
echo asdf#qwert yuiop

echo asdf #qwert yuiop