fix: Avoid O(n^2) backtracking in inline link href regex (#4013)

This commit is contained in:
Anh Hong
2026-07-09 11:04:39 -06:00
committed by GitHub
parent 33928d0663
commit a0098085f4
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -395,7 +395,7 @@ const _inlineLabel = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!
const link = edit(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/)
.replace('label', _inlineLabel)
.replace('href', /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/)
.replace('href', /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/)
.replace('title', /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/)
.getRegex();
@@ -0,0 +1,4 @@
module.exports = {
markdown: '[](' + ' '.repeat(50000),
html: '<p>[](' + ' '.repeat(50000) + '</p>',
};