fix: avoid cubic backtracking on unicode whitespace in a link destination (#4106)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
spokodev
2026-10-05 09:36:37 -06:00
committed by GitHub
co-authored by Claude Opus 5
parent c18a64fa5e
commit 0d2022025d
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -457,7 +457,7 @@ const _inlineLabel = edit(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?
.replace('brackets', _inlineLabelBrackets)
.getRegex();
const link = edit(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/)
const link = edit(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/)
.replace('label', _inlineLabel)
.replace('href', /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/)
.replace('title', /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/)
@@ -0,0 +1,8 @@
// Same shape as quadratic_link_empty_href, with the ASCII space replaced by U+00A0.
// The gap before a link destination used to be \s*, which also matches unicode
// whitespace, while the destination class only excluded ASCII space, tab and newline.
// A run of unicode whitespace could therefore be split between the two in n ways.
module.exports = {
markdown: '[](' + ' '.repeat(50000),
html: `<p>[](${' '.repeat(50000)}</p>`,
};