From c7d3d995d6439e680d3ed18d478ad23a389e900b Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Tue, 28 Jul 2020 20:17:52 -0400 Subject: [PATCH] fix(parser) Freezing issue with illegal 0 width illegals (#2524) - backporting fix from v10 series --- src/highlight.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/highlight.js b/src/highlight.js index 7adb239a86..ddc1eba27e 100644 --- a/src/highlight.js +++ b/src/highlight.js @@ -707,6 +707,16 @@ https://highlightjs.org/ mode_buffer += codeToHighlight.slice(match.index, match.index + 1); return 1; } + + // edge case for when illegal matches $ (end of line) which is technically + // a 0 width match but not a begin/end match so it's not caught by the + // first handler (when ignoreIllegals is true) + // https://github.com/highlightjs/highlight.js/issues/2522 + if (lastMatch.type==="illegal" && lexeme === "") { + mode_buffer += codeToHighlight.slice(match.index, match.index + 1); + return 1; + } + lastMatch = match; if (match.type==="begin") {