Fix linkcheck uppercase scheme handling - #14640
Draft
aryansk wants to merge 1 commit into
Draft
Conversation
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#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sphinx's linkcheck builder uses a case-sensitive regex (
([a-z]+:)?//) and case-sensitivestartswithchecks forhttp:/https:to detect external links. Per RFC 3986 §3.1, URI schemes are case-insensitive. URIs with uppercase schemes likeFTP://example.test/fileorHTTP://example.comare not recognized:FTP://failsuri_re.match(only lowercase[a-z]), so it falls through to the local-file existence check and is reported as[broken]instead of[unchecked].HTTP:///HTTPS://failsuri.startswith(('http:', 'https:')), also falling through to local-file logic.Fixes #14541
Reproduction from the issue:
Change
The smallest complete fix in
sphinx/builders/linkcheck.py:uri_re = re.compile('([a-z]+:)?//', re.IGNORECASE)— recognize uppercase schemesuri.lower().startswith(('http:', 'https:'))— handleHTTP:///HTTPS://correctlyuri.lower().startswith(('#', 'mailto:', 'tel:'))— consistent forMAILTO:/TEL:(also case-insensitive per RFC)Why this approach
re.IGNORECASEpreserves the existing pattern while matching uppercase per RFC 3986.lower().startswithis the standard case-insensitive prefix check and matches howurlsplit/urlparsenormalize schemes.Testing
Manual reproduction with patched code:
Existing linkcheck suite:
Documentation and release impact
Review notes
ftp:/archive.zipstill require//per maintainer discussion on linkcheck reports uppercase-scheme URIs as broken #14541; not changed here.AI disclosure
AI assistance was used (Muse Spark) for code analysis and fix drafting. All changes were manually reviewed, tested locally, and verified against the reproduction case. The contributor understands and can explain the submitted code.