linkcheck: treat URI schemes as case-insensitive (RFC 3986) - #14599
Open
sudorm-rf0 wants to merge 1 commit into
Open
linkcheck: treat URI schemes as case-insensitive (RFC 3986)#14599sudorm-rf0 wants to merge 1 commit into
sudorm-rf0 wants to merge 1 commit into
Conversation
…oc#14541) Per RFC 3986, URI schemes are case-insensitive, but linkcheck used a case-sensitive regex ('([a-z]+:)?//') to detect non-HTTP schemes. Uppercase schemes such as 'FTP://' were not recognised as external links and were wrongly reported as [broken] instead of [unchecked]. Make the regex case-insensitive. Fixes sphinx-doc#14541.
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.
Hi,
This fixes a
linkcheckbug where URIs with an uppercase scheme (e.g.FTP://example.test/file) were reported as[broken], while the lowercase formftp://was correctly reported as[unchecked].AI assistance disclosure (per the AI policy): I used an AI coding assistant to help produce the initial patch and the regression test. I have reviewed the diff, understand exactly what it does, and can explain it below. I am opening this PR myself after checking it.
What's going on / why I think this is the right fix
Per RFC 3986 §3.1, URI schemes are case-insensitive, so
FTP://andftp://are the same scheme. Sphinx'slinkcheckdecides whether a link is "external" (a non-HTTP scheme) with this regex insphinx/builders/linkcheck.py:Because the character class is
[a-z]only, an uppercase scheme likeFTP://never matches, solinkcheckdoes not recognise it as an external link. It then falls through to the local-file existence check and reports[broken]for a URI that is actually a remote FTP link.The fix is a one-liner: make the regex case-insensitive.
Now
FTP://,SSH://, etc. are treated exactly like their lowercase forms and reported as[unchecked].http:/https:links are unaffected (they are still checked normally), and nothing else in the matching logic changes.How I verified it
tests/test_builders/test_build_linkcheck.py::test_linkcheck_uppercase_scheme_is_uncheckedcoveringFTP://,ftp://, andSSH://. It reportsbrokenon the unpatched code anduncheckedwith the fix.pytest tests/test_builders/test_build_linkcheck.py→ 51 passed, no regressions.ruff check/ruff format --checkclean on the changed files.Fixes #14541.