From 52e81ea85671a85dd5e393a568d55f8559613ddc Mon Sep 17 00:00:00 2001 From: aryansk Date: Tue, 25 Aug 2026 10:47:03 +0530 Subject: [PATCH] Fix linkcheck uppercase scheme handling The linkcheck builder used case-sensitive checks for URI schemes. URIs with uppercase schemes like FTP:// or HTTP:// were not recognized as external links and were incorrectly reported as broken due to falling through to the local file existence check. - Make uri_re case-insensitive (re.IGNORECASE) to correctly identify non-HTTP schemes regardless of case - Make the http/https and mailto/tel prefix checks case-insensitive via uri.lower().startswith() Fixes sphinx-doc/sphinx#14541 AI assistance disclosure: Muse Spark used for code analysis and fix generation; all changes reviewed, tested locally (48 linkcheck tests passing) and verified against the reproduction case. --- sphinx/builders/linkcheck.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 5889e75d126..b04c5cbe329 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -61,7 +61,7 @@ class _Status(StrEnum): logger = logging.getLogger(__name__) # matches to foo:// and // (a protocol relative URL) -uri_re = re.compile('([a-z]+:)?//') +uri_re = re.compile('([a-z]+:)?//', re.IGNORECASE) DEFAULT_REQUEST_HEADERS = { 'Accept': 'text/html,application/xhtml+xml;q=0.9,*/*;q=0.8', @@ -466,9 +466,9 @@ def _check(self, docname: str, uri: str, hyperlink: Hyperlink) -> _URIProperties ) return _Status.IGNORED, info, 0 - if len(uri) == 0 or uri.startswith(('#', 'mailto:', 'tel:')): + if len(uri) == 0 or uri.lower().startswith(('#', 'mailto:', 'tel:')): return _Status.UNCHECKED, '', 0 - if not uri.startswith(('http:', 'https:')): + if not uri.lower().startswith(('http:', 'https:')): if uri_re.match(uri): # Non-supported URI schemes (ex. ftp) return _Status.UNCHECKED, '', 0