From c74d07d50cf028db1b977adfa44b53fa7913675c Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Sat, 15 Feb 2020 19:11:24 -0500 Subject: [PATCH 1/2] fix(javascript) comma is allowed in a "value container" - fixes case where a regex would not be detected if it was anything other than the first parameter of a function call - in some cases this could actually cause the whole snippet to be flagged as illegal if the regex contained characters that were invalid at the top level (such as #) This complexity is because we only detect regexs inside "value containers" to prevent false positivies. This issue was found when asking Highlight.js to highlight it's own non-minified 1.2mb browser build. --- src/languages/javascript.js | 4 ++++ test/markup/javascript/method-call.expect.txt | 5 +++++ test/markup/javascript/method-call.txt | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/src/languages/javascript.js b/src/languages/javascript.js index 4ec89f3ca7..7cf8a0d532 100644 --- a/src/languages/javascript.js +++ b/src/languages/javascript.js @@ -189,6 +189,9 @@ export default function(hljs) { } ] }, + { // could be a comma delimited list of params to a function call + begin: /,/, relevance: 0, + }, { className: '', begin: /\s/, @@ -229,6 +232,7 @@ export default function(hljs) { { begin: /\$[(.]/ // relevance booster for a pattern common to JS libs: `$(something)` and `$.something` }, + hljs.METHOD_GUARD, { // ES6 class className: 'class', diff --git a/test/markup/javascript/method-call.expect.txt b/test/markup/javascript/method-call.expect.txt index 25b4a6adab..c4f40657b0 100644 --- a/test/markup/javascript/method-call.expect.txt +++ b/test/markup/javascript/method-call.expect.txt @@ -1 +1,6 @@ x.continue(0); + +x = [ +hljs.COMMENT(/\{%\s*comment\s*%}/, /\{%\s*endcomment\s*%}/), +hljs.COMMENT(/\{#/, /#}/), +] diff --git a/test/markup/javascript/method-call.txt b/test/markup/javascript/method-call.txt index e4e6cc47a4..f5ea219ec9 100644 --- a/test/markup/javascript/method-call.txt +++ b/test/markup/javascript/method-call.txt @@ -1 +1,7 @@ x.continue(0); + +x = [ +hljs.COMMENT(/\{%\s*comment\s*%}/, /\{%\s*endcomment\s*%}/), +hljs.COMMENT(/\{#/, /#}/), +] + From 46c067f426d8acbe960afebe0b646bb28bb17086 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Sun, 16 Feb 2020 21:46:15 -0500 Subject: [PATCH 2/2] update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index c4ff353ebc..323bab5cde 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Core Changes: Language Improvements: +- fix(javascript) comma is allowed in a "value container" (#2403) [Josh Goebel][] - enh(apache) add `deny` and `allow` keywords [Josh Goebel][] - enh(apache) highlight numeric attributes values [Josh Goebel][] - enh(apache) highlight IP addresses, ports, and strings in sections [Josh Goebel][]