diff --git a/CHANGES.md b/CHANGES.md
index 9157f67300..ac9c8d48c9 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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:
@@ -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
diff --git a/src/languages/bash.js b/src/languages/bash.js
index 17295c7f54..c12c3c18bc 100644
--- a/src/languages/bash.js
+++ b/src/languages/bash.js
@@ -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: [
@@ -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,
diff --git a/test/markup/bash/not-comments.expect.txt b/test/markup/bash/not-comments.expect.txt
new file mode 100644
index 0000000000..ab12864283
--- /dev/null
+++ b/test/markup/bash/not-comments.expect.txt
@@ -0,0 +1,3 @@
+echo asdf#qwert yuiop
+
+echo asdf
diff --git a/test/markup/bash/not-comments.txt b/test/markup/bash/not-comments.txt
new file mode 100644
index 0000000000..b8f6f88383
--- /dev/null
+++ b/test/markup/bash/not-comments.txt
@@ -0,0 +1,3 @@
+echo asdf#qwert yuiop
+
+echo asdf #qwert yuiop