fix: avoid quadratic time on long local part before @ in GFM text (#4225)

This commit is contained in:
Gss
2026-11-16 11:20:08 -07:00
committed by GitHub
parent b9e3824233
commit c6b22e89ba
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -604,7 +604,7 @@ const inlineGfm: Record<InlineKeys, RegExp> = {
.getRegex(),
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,
text: edit(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|wwwStart|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/)
text: edit(/^(?:[A-Za-z0-9.+-]+(?=@)|[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|wwwStart|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/)
.replace('protocol', _caseInsensitiveProtocol)
.replace(/emailProtocol/g, /(?:mailto|xmpp):/)
// GFM: a www autolink starts only at the beginning of a line, after whitespace or after
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
markdown: `${'a'.repeat(50000)}@`,
html: `<p>${'a'.repeat(50000)}@</p>`,
};