From 84beefb3eb24dbf25c526467a2a3906b9afe11e8 Mon Sep 17 00:00:00 2001
From: Aman Jha <99260113+amanjhacodes55@users.noreply.github.com>
Date: Mon, 2 Nov 2026 20:19:34 +0530
Subject: [PATCH] fix: start a GFM www autolink only at a word boundary (#4166)
Co-authored-by: aman
Co-authored-by: Claude Opus 5.5
---
src/rules.ts | 5 ++++-
test/specs/new/autolink_www_word_start.html | 13 +++++++++++++
test/specs/new/autolink_www_word_start.md | 13 +++++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
create mode 100644 test/specs/new/autolink_www_word_start.html
create mode 100644 test/specs/new/autolink_www_word_start.md
diff --git a/src/rules.ts b/src/rules.ts
index d74f2e23..81db2dc3 100644
--- a/src/rules.ts
+++ b/src/rules.ts
@@ -586,9 +586,12 @@ const inlineGfm: Record = {
.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]*?(?:(?=[\\xwww.example.com
+
+a.www.example.com
+
+<www.example.com>
+
+visit www.example.com
+
+www.example.com
+
+(www.example.com)
+
+www.example.com
diff --git a/test/specs/new/autolink_www_word_start.md b/test/specs/new/autolink_www_word_start.md
new file mode 100644
index 00000000..87b322b7
--- /dev/null
+++ b/test/specs/new/autolink_www_word_start.md
@@ -0,0 +1,13 @@
+xwww.example.com
+
+a.www.example.com
+
+
+
+visit www.example.com
+
+*www.example.com*
+
+(www.example.com)
+
+_www.example.com_