Skip to content

fix: check links below the sub-path an app is served at - #472

Merged
JuroOravec merged 1 commit into
mainfrom
fix/link-check-sub-path
Oct 28, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/link-check-sub-path

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

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:

Framework Setting Change
FastAPI FastAPI(root_path="/shop") read in contrib/fastapi.py, used unchanged, as Starlette's get_route_path uses it
Flask APPLICATION_ROOT read in contrib/flask.py; a trailing / is ignored, as Werkzeug ignores it
Django FORCE_SCRIPT_NAME already read through get_script_prefix(); contrib/django.py now uses the same helper
  • A link that does not start with the sub-path, such as /blog, is reported, because the browser sends it outside the app. Suggestions keep the sub-path.
  • The sub-path alone (/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.
  • Flask binds its URL map below the sub-path, so a redirect_to that leaves the sub-path is reported, as a browser would see it.
  • Flask also finds a link to Citry's own routes below the sub-path, such as /shop/citry/citry.js, because mount() sends those requests to Citry in front of the URL map.
  • A value without a leading / 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

  • A sub-path that only the server sets (gunicorn's 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".
  • A link to /citry/... without the sub-path is still counted as found before any checker runs (is_citry_path in _path_checks.py). The docs already say such paths are not checked.
  • PR docs: clarify link and slot data checks in the IDE docs #464 edits the same docs page, so one of the two will need a small merge.

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.py compares the checker with Flask's and FastAPI's test clients below a sub-path. It also tests:
    • links outside the sub-path;
    • a trailing-slash root_path;
    • a value without a leading /;
    • the sub-path alone, with and without Starlette's slash redirect, and in Django;
    • Citry mounted at a custom prefix under Flask;
    • APPLICATION_ROOT changed after mount().

The citry suite passes, as do mypy (also with --platform linux), ruff and scripts/validate.py.

Part of #465.

🤖 Generated with Claude Code

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
JuroOravec force-pushed the fix/link-check-sub-path branch from 7740c03 to e7ccf7e Compare October 28, 2026 15:04
@JuroOravec
JuroOravec merged commit 206e333 into main Oct 28, 2026
0 of 30 checks passed
@JuroOravec
JuroOravec deleted the fix/link-check-sub-path branch October 28, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant