perf: fix backtracking in padantic html (#4173)

This commit is contained in:
Tony Brix
2026-11-02 08:01:25 -07:00
committed by GitHub
parent 5cb03bd9a2
commit 2d4a23c50e
4 changed files with 18 additions and 3 deletions
+3 -3
View File
@@ -273,9 +273,9 @@ const blockGfm: Record<BlockKeys, RegExp> = {
const blockPedantic: Record<BlockKeys, RegExp> = {
...blockNormal,
html: edit(
'^ *(?:comment *(?:\\n|\\s*$)'
+ '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
+ '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
'^ *(?:comment(?: *\\n|\\s*$)'
+ '|<(tag)[\\s\\S]+?</\\1>(?: *\\n{2,}|\\s*$)' // closed tag
+ '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?>(?: *\\n{2,}|\\s*$))')
.replace('comment', _comment)
.replace(/tag/g, '(?!(?:'
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
options: { pedantic: true, gfm: false },
markdown: '<test>a</test>' + ' '.repeat(50000) + 'b',
html: '<p><test>a</test> b</p>\n',
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
options: { pedantic: true, gfm: false },
markdown: '<!-->' + ' '.repeat(50000) + 'b',
html: '<!--> b\n',
};
@@ -0,0 +1,5 @@
module.exports = {
options: { pedantic: true, gfm: false },
markdown: '<test/>' + ' '.repeat(50000) + 'b',
html: '<p><test/> b</p>\n',
};