Repository navigation
fix: check links below the sub-path an app is served at - #472
Merged
Merged
Conversation
The unknown-URL link check compared links such as /shop/about with the app's routes as if the app were served at the site root, so it reported correct links for a FastAPI app with root_path or a Flask app with APPLICATION_ROOT. The FastAPI and Flask checkers now read that setting and remove the sub-path before they ask the framework, using each framework's own rules for the value. A link that does not start with the sub-path is reported, and suggestions keep the sub-path. Flask binds its URL map below the sub-path, so a redirect_to that leaves it is reported. The Django checker uses the same helper, so a link to the sub-path alone reaches the project root, as it does in Django. A sub-path that only the server sets (gunicorn SCRIPT_NAME, uvicorn --root-path) is still unseen outside a request; the docs say to set the framework's own setting to the same value. Part of #465. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
fix/link-check-sub-path
branch
from
October 28, 2026 15:04
7740c03 to
e7ccf7e
Compare
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.
What this does
The unknown-URL link check (
citry.template.unknown-url) reported correct links as missing when the app is served below a sub-path, such as/shop. The template writes/shop/cart, while the app's route is/cart.Each framework already has a setting that states the sub-path outside a request. The checkers now read it and remove the sub-path from a link before they ask the framework:
FastAPI(root_path="/shop")contrib/fastapi.py, used unchanged, as Starlette'sget_route_pathuses itAPPLICATION_ROOTcontrib/flask.py; a trailing/is ignored, as Werkzeug ignores itFORCE_SCRIPT_NAMEget_script_prefix();contrib/django.pynow uses the same helper/blog, is reported, because the browser sends it outside the app. Suggestions keep the sub-path./shop) is handled as each framework handles it: Flask and Django serve their root, and Starlette routes an empty path, which only the trailing-slash redirect serves.redirect_tothat leaves the sub-path is reported, as a browser would see it./shop/citry/citry.js, becausemount()sends those requests to Citry in front of the URL map./matches no link. Starlette routes nothing below it, and Flask and Django build broken links from it.No public setting is added.
Not in this PR
SCRIPT_NAME, uvicorn's--root-path, which is the Django case in the issue's title) exists only during a request, so the check still cannot see it. The docs say to set the framework's own setting to the same value, or turn the rule off. A Citry setting for this case would repeat a value each framework already has, so it is left for a decision. That is why this PR says "Part of Link check reports correct links for a Django app whose sub-path comes from the server #465"./citry/...without the sub-path is still counted as found before any checker runs (is_citry_pathin_path_checks.py). The docs already say such paths are not checked.Docs and tests
docs_site/content/ide/template-linting.md: the paragraph that said to turn the rule off for a sub-path app now explains the sub-path handling, with a table of the three settings.CHANGELOG.md: one sentence on the unreleased unknown-URL entry.tests/test_path_checks.pycompares the checker with Flask's and FastAPI's test clients below a sub-path. It also tests:root_path;/;APPLICATION_ROOTchanged aftermount().The citry suite passes, as do mypy (also with
--platform linux), ruff andscripts/validate.py.Part of #465.
🤖 Generated with Claude Code