From 4fa4633c93307bb808c9023570a43dcfdd92e281 Mon Sep 17 00:00:00 2001 From: Aryan Rajesh Ganjoo <51299383+AryanRG@users.noreply.github.com> Date: Wed, 14 Oct 2026 13:37:00 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Avoid=20gfm=5Fautolink=20?= =?UTF-8?q?hangs=20in=20link=20labels=20(#160)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Decline silent autolink matches so link-label scanning can handle structural delimiters without looping or consuming the closing bracket. --- CHANGELOG.md | 4 +++ mdit_py_plugins/gfm_autolink/index.py | 9 +++-- tests/fixtures/gfm_autolink.md | 51 +++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1b78b3..ca180d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## Unreleased + +- 🐛 FIX: `gfm_autolink` hang on autolink-like text in link labels (#160) + ## 0.7.0 - 2026-07-19 - ✨ NEW: Add section reference plugin (`section_ref`) (#144) diff --git a/mdit_py_plugins/gfm_autolink/index.py b/mdit_py_plugins/gfm_autolink/index.py index 48de4b7..360ba67 100644 --- a/mdit_py_plugins/gfm_autolink/index.py +++ b/mdit_py_plugins/gfm_autolink/index.py @@ -159,7 +159,10 @@ def _www_inline_rule(state: StateInline, silent: bool) -> bool: label = src[pos : pos + length] if silent: - return True + # Autolinks are only recognised when emitting tokens. When skipping + # silently (e.g. scanning a link label), report no match so the parser + # steps over this text as plain characters (#160). + return False full_url = state.md.normalizeLink(url) if not state.md.validateLink(full_url): @@ -223,7 +226,7 @@ def _protocol_rule(state: StateInline, silent: bool) -> bool: label = combined[:total_len] if silent: - return True + return False # see _www_inline_rule return _create_autolink(state, bscan_len, total_len, full_url, label) @@ -291,5 +294,5 @@ def _email_rule(state: StateInline, silent: bool) -> bool: url = "mailto:" + email_text if silent: - return True + return False # see _www_inline_rule return _create_autolink(state, local_len, total_len, url, email_text) diff --git a/tests/fixtures/gfm_autolink.md b/tests/fixtures/gfm_autolink.md index 6a715f3..03e369f 100644 --- a/tests/fixtures/gfm_autolink.md +++ b/tests/fixtures/gfm_autolink.md @@ -223,3 +223,54 @@ xmpp:foo@bar.baz/txt/bin .
. + +GFM autolink: www in link text after leading text (#160) +. +see [www.example.com](https://example.com) +. +see www.example.com
+. + +GFM autolink: www in emphasized link text (#160) +. +[link *www.example.com*](https://example.org) +. + +. + +GFM autolink: www in image alt text (#160) +. +see  +. +see 
see www.example.com
+. + +GFM autolink: protocol in link text with preceding text (#160) +. +https[x https://example.com](u) +. + +. + +GFM autolink: email in link text with preceding text (#160) +. +a[x b@example.com](u) +. + +. + +GFM autolink: mailto in link text with preceding text (#160) +. +mailto[x mailto:a@example.com](u) +. +mailtox mailto:a@example.com
+.