From 89409b7648558069da3f6a6206095b25367c1104 Mon Sep 17 00:00:00 2001
From: RavSinghChandan
Date: Fri, 4 Dec 2026 18:20:14 +0530
Subject: [PATCH] Match the mailto scheme of an auto-mail link in any case
---
docs/changelog.md | 2 ++
markdown/inlinepatterns.py | 2 +-
tests/test_syntax/inline/test_autolinks.py | 9 +++++++++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/docs/changelog.md b/docs/changelog.md
index 2020ed858..da06d4f6e 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -16,6 +16,8 @@ See the [Contributing Guide](contributing.md) for details.
### Fixed
+* Fix a doubled `mailto:` in automatic email links which write the scheme in
+ upper or mixed case, such as ``.
* Fix cubic processing time in the `legacy_attrs` extension for text with many
`{@` that are not closed by a `}` (#1721).
* Footnote definitions are no longer recognized within a footnote definition,
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py
index 46db28a88..c77eb445a 100644
--- a/markdown/inlinepatterns.py
+++ b/markdown/inlinepatterns.py
@@ -1438,7 +1438,7 @@ def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element, int,
""" Return an [`Element`][xml.etree.ElementTree.Element] containing a `mailto` link of `group(1)`. """
el = etree.Element('a')
email = self.unescape(m.group(1))
- if email.startswith("mailto:"):
+ if email.lower().startswith("mailto:"):
email = email[len("mailto:"):]
def codepoint2name(code: int) -> str:
diff --git a/tests/test_syntax/inline/test_autolinks.py b/tests/test_syntax/inline/test_autolinks.py
index 751ef1348..6e05a0f0a 100644
--- a/tests/test_syntax/inline/test_autolinks.py
+++ b/tests/test_syntax/inline/test_autolinks.py
@@ -108,6 +108,15 @@ def test_mailto_email_address(self):
'.org
'
)
+ def test_mailto_email_address_in_any_case(self):
+ expected = (
+ ''
+ 'a@b.co
'
+ )
+ for scheme in ('MAILTO:', 'Mailto:'):
+ with self.subTest(scheme=scheme):
+ self.assertMarkdownRenders('<{}a@b.co>'.format(scheme), expected)
+
def test_email_address_with_ampersand(self):
self.assertMarkdownRenders(
'',