-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
linkcheck: Allow case-insensitive URL comparisons #14046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AA-Turner
merged 50 commits into
sphinx-doc:master
from
FazeelUsmani:linkcheck_case_insensitive
Nov 24, 2025
+143
−2
Merged
Changes from 32 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
63e108c
Update configuration.rst
FazeelUsmani caae7eb
Add linkcheck_ignore_case config option
FazeelUsmani 9e6dd40
Update i18n.py
FazeelUsmani eccd6d7
fixed the failing test test_numfig_disabled_warn
FazeelUsmani 6300483
Enable case-insensitive URL and anchor checking for linkcheck builder
FazeelUsmani b61366c
strip ANSI color codes from stderr before assertion
FazeelUsmani 7ea45c6
fixed the failing test test_connect_to_selfsigned_fails
FazeelUsmani 99a5dc0
Update test_build_linkcheck.py
FazeelUsmani f99651f
Merge branch 'master' into linkcheck_case_insensitive
FazeelUsmani ac12d63
Update linkcheck.py
FazeelUsmani 1a0d9ed
Update test_build_linkcheck.py
FazeelUsmani d115b1e
Update test_build_linkcheck.py
FazeelUsmani 0075419
fix ruff check linkcheck.py
FazeelUsmani 4eceef2
fix ruff check test_build_linkcheck.py
FazeelUsmani e772df9
Update configuration.rst
FazeelUsmani 14ded5b
Update configuration.rst
FazeelUsmani 386d4ac
Update configuration.rst
FazeelUsmani 53a47e3
Update doc/usage/configuration.rst
FazeelUsmani 3e545f3
Update i18n.py (reert \)
FazeelUsmani d9940da
Use .casefold() for case-insensitive URL comparison
FazeelUsmani 322fcf5
Update test_build_linkcheck.py (revert)
FazeelUsmani cfcbef2
Update test_build_linkcheck.py (revert)
FazeelUsmani 2c4567d
restore original pytest markers
FazeelUsmani c18d573
Removed the duplicate @pytest.mark.sphinx
FazeelUsmani 07b1795
Removed test_linkcheck_anchors_remain_case_sensitive
FazeelUsmani bc8fa7c
Rename linkcheck_ignore_case to linkcheck_case_insensitive and update…
FazeelUsmani 029a720
Fix ruff format check
FazeelUsmani 539adaa
remove unused code paths
FazeelUsmani ae5708f
Merge branch 'master' into linkcheck_case_insensitive
FazeelUsmani 66ae54d
Remove unused test parameter from numfig test
FazeelUsmani 5bc9f2d
Tests: Add complete coverage for linkcheck case sensitivity tests
FazeelUsmani eaa1caa
Refactor linkcheck case sensitivity: rename config and fix fragment h…
FazeelUsmani 57e8b3c
Improve formatting and update config value handling
FazeelUsmani 5dffff4
Update tests/test_builders/test_build_linkcheck.py
FazeelUsmani 5e08ab3
Remove deprecated linkcheck_case_insensitive config handling
FazeelUsmani 45cf720
Merge branch 'linkcheck_case_insensitive' of github.com:FazeelUsmani/…
FazeelUsmani 06663cf
Refactor linkcheck tests: rename handler for case sensitivity and sim…
FazeelUsmani 5615ffc
Add support for case-insensitive URL checking in linkcheck builder
FazeelUsmani 842b756
restore @pytest.mark.test_params and update documentation
FazeelUsmani 1fe4293
efactor linkcheck case sensitivity tests with dynamic path handler
FazeelUsmani 8c7648b
"Update test document with path1 and path2 for case sensitivity tests
FazeelUsmani d95224b
Apply ruff formatting
FazeelUsmani 422b2d5
Refactor linkcheck case sensitivity tests per review feedback
FazeelUsmani a3744b0
ruff format
FazeelUsmani a53c44a
Update tests/test_builders/test_build_linkcheck.py
FazeelUsmani 4457493
dd test case for non-redirecting URL in linkcheck case sensitivity tests
FazeelUsmani 515d0c5
Merge branch 'linkcheck_case_insensitive' of github.com:FazeelUsmani/…
FazeelUsmani cf03035
Merge branch 'master' into linkcheck_case_insensitive
AA-Turner a3d6a37
misc tweaks; rename to linkcheck_case_insensitive_urls
AA-Turner 05d1049
fixup
AA-Turner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Empty config for linkcheck case sensitivity tests |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| `local server path <http://localhost:7777/path>`_ |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1439,3 +1439,87 @@ def test_linkcheck_exclude_documents(app: SphinxTestApp) -> None: | |
| 'uri': 'https://www.sphinx-doc.org/this-is-another-broken-link', | ||
| 'info': 'br0ken_link matched br[0-9]ken_link from linkcheck_exclude_documents', | ||
| } in content | ||
|
|
||
|
|
||
| class CaseSensitiveHandler(BaseHTTPRequestHandler): | ||
|
||
| """Simple test server for case sensitivity tests.""" | ||
|
|
||
| protocol_version = 'HTTP/1.1' | ||
|
|
||
| def do_HEAD(self): | ||
| if self.path == '/path': | ||
| # Redirect lowercase /path to uppercase /Path | ||
| self.send_response(301, 'Moved Permanently') | ||
| self.send_header('Location', f'http://{self.headers["Host"]}/Path') | ||
FazeelUsmani marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.send_header('Content-Length', '0') | ||
| self.end_headers() | ||
| elif self.path == '/Path': | ||
| self.send_response(200, 'OK') | ||
| self.send_header('Content-Length', '0') | ||
| self.end_headers() | ||
| else: | ||
| self.send_response(404, 'Not Found') | ||
| self.send_header('Content-Length', '0') | ||
| self.end_headers() | ||
|
|
||
| def do_GET(self): | ||
| if self.path == '/path': | ||
| # Redirect lowercase /path to uppercase /Path | ||
| self.send_response(301, 'Moved Permanently') | ||
| self.send_header('Location', f'http://{self.headers["Host"]}/Path') | ||
| self.send_header('Content-Length', '0') | ||
| self.end_headers() | ||
| elif self.path == '/Path': | ||
| content = b'ok\n\n' | ||
| self.send_response(200, 'OK') | ||
| self.send_header('Content-Length', str(len(content))) | ||
| self.end_headers() | ||
| self.wfile.write(content) | ||
| else: | ||
| self.send_response(404, 'Not Found') | ||
| self.send_header('Content-Length', '0') | ||
| self.end_headers() | ||
|
|
||
|
|
||
| @pytest.mark.sphinx( | ||
| 'linkcheck', | ||
| testroot='linkcheck-case-check', | ||
| freshenv=True, | ||
| confoverrides={'linkcheck_case_sensitive': True}, | ||
| ) | ||
| def test_linkcheck_case_sensitive(app: SphinxTestApp) -> None: | ||
| """Test that case-sensitive checking is the default behavior.""" | ||
| with serve_application(app, CaseSensitiveHandler) as address: | ||
| app.build() | ||
|
|
||
| content = (app.outdir / 'output.json').read_text(encoding='utf8') | ||
| rows = [json.loads(x) for x in content.splitlines()] | ||
| rowsby = {row['uri']: row for row in rows} | ||
|
|
||
| # With case-sensitive checking, a URL that redirects to different case | ||
| # should be marked as redirected | ||
| lowercase_uri = f'http://{address}/path' | ||
| assert lowercase_uri in rowsby, f'Expected {lowercase_uri} to be checked' | ||
| assert rowsby[lowercase_uri]['status'] == 'redirected' | ||
AA-Turner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @pytest.mark.sphinx( | ||
| 'linkcheck', | ||
| testroot='linkcheck-case-check', | ||
| freshenv=True, | ||
| confoverrides={'linkcheck_case_sensitive': False}, | ||
| ) | ||
| def test_linkcheck_case_insensitive(app: SphinxTestApp) -> None: | ||
AA-Turner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Test that linkcheck_case_sensitive=False ignores case differences in URLs.""" | ||
| with serve_application(app, CaseSensitiveHandler) as address: | ||
| app.build() | ||
|
|
||
| content = (app.outdir / 'output.json').read_text(encoding='utf8') | ||
| rows = [json.loads(x) for x in content.splitlines()] | ||
| rowsby = {row['uri']: row for row in rows} | ||
|
|
||
| # With case-insensitive checking, a URL that differs only in case | ||
| # should be marked as working | ||
| lowercase_uri = f'http://{address}/path' | ||
| assert lowercase_uri in rowsby, f'Expected {lowercase_uri} to be checked' | ||
| assert rowsby[lowercase_uri]['status'] == 'working' | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.