Skip to content

Commit c7d3d99

Browse files
committed
fix(parser) Freezing issue with illegal 0 width illegals (#2524)
- backporting fix from v10 series
1 parent dbfffac commit c7d3d99

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/highlight.js

+10
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,16 @@ https://highlightjs.org/
707707
mode_buffer += codeToHighlight.slice(match.index, match.index + 1);
708708
return 1;
709709
}
710+
711+
// edge case for when illegal matches $ (end of line) which is technically
712+
// a 0 width match but not a begin/end match so it's not caught by the
713+
// first handler (when ignoreIllegals is true)
714+
// https://github.com/highlightjs/highlight.js/issues/2522
715+
if (lastMatch.type==="illegal" && lexeme === "") {
716+
mode_buffer += codeToHighlight.slice(match.index, match.index + 1);
717+
return 1;
718+
}
719+
710720
lastMatch = match;
711721

712722
if (match.type==="begin") {

0 commit comments

Comments
 (0)