fix: start a GFM www autolink only at a word boundary (#4166)

Co-authored-by: aman <aman@pronnel.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aman Jha
2026-11-02 07:49:34 -07:00
committed by GitHub
co-authored by aman Claude Opus 5.5
parent eab1e483fe
commit 84beefb3eb
3 changed files with 30 additions and 1 deletions
+4 -1
View File
@@ -586,9 +586,12 @@ 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:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/)
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.!#$%&'*+\/=?_`{\|}~-]+@))))/)
.replace('protocol', _caseInsensitiveProtocol)
.replace(/emailProtocol/g, /(?:mailto|xmpp):/)
// GFM: a www autolink starts only at the beginning of a line, after whitespace or after
// `*`, `_`, `~` or `(`. Without lookbehind support, keep stopping at every `www.`.
.replace('wwwStart', supportsLookbehind ? '(?<![^\\s*_~(])www\\.' : 'www\\.')
.getRegex(),
};
@@ -0,0 +1,13 @@
<p>xwww.example.com</p>
<p>a.www.example.com</p>
<p>&lt;www.example.com&gt;</p>
<p>visit <a href="http://www.example.com">www.example.com</a></p>
<p><em><a href="http://www.example.com">www.example.com</a></em></p>
<p>(<a href="http://www.example.com">www.example.com</a>)</p>
<p><em><a href="http://www.example.com">www.example.com</a></em></p>
+13
View File
@@ -0,0 +1,13 @@
xwww.example.com
a.www.example.com
<www.example.com>
visit www.example.com
*www.example.com*
(www.example.com)
_www.example.com_