From 149039c393ec1ea06a821b396944bc23cb7974a9 Mon Sep 17 00:00:00 2001 From: Shashank Yadav <65058495+shashank11yadav@users.noreply.github.com> Date: Wed, 25 Nov 2026 12:20:59 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Match=20linkify=20schemes?= =?UTF-8?q?=20as=20ASCII=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With re.IGNORECASE on a str pattern, [a-z] also matches U+017F (long s) and U+212A (Kelvin sign), so a bare URL right after either character was read as part of the scheme and left unlinked. Add re.ASCII so the scheme follows RFC 3986, where ALPHA is ASCII only. --- markdown_it/rules_inline/linkify.py | 4 +++- tests/test_linkify.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/markdown_it/rules_inline/linkify.py b/markdown_it/rules_inline/linkify.py index 3669396e..98ffd8b2 100644 --- a/markdown_it/rules_inline/linkify.py +++ b/markdown_it/rules_inline/linkify.py @@ -5,7 +5,9 @@ from .state_inline import StateInline # RFC3986: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) -SCHEME_RE = re.compile(r"(?:^|[^a-z0-9.+-])([a-z][a-z0-9.+-]*)$", re.IGNORECASE) +SCHEME_RE = re.compile( + r"(?:^|[^a-z0-9.+-])([a-z][a-z0-9.+-]*)$", re.IGNORECASE | re.ASCII +) def linkify(state: StateInline, silent: bool) -> bool: diff --git a/tests/test_linkify.py b/tests/test_linkify.py index c1905399..ddc741da 100644 --- a/tests/test_linkify.py +++ b/tests/test_linkify.py @@ -22,3 +22,12 @@ def test_token_levels(): assert link_open.level == 0 assert link_text.level == 1 assert link_close.level == 0 + + +@pytest.mark.parametrize("prefix", ["\N{LATIN SMALL LETTER LONG S}", "\N{KELVIN SIGN}"]) +def test_linkify_scheme_is_ascii_only(prefix): + """Letters that case-fold to ASCII are not scheme characters.""" + mdit = MarkdownIt(options_update={"linkify": True}).enable("linkify") + assert mdit.render(f"{prefix}http://example.com") == ( + f'
{prefix}http://example.com
\n' + )