Repository navigation
fix(routing)!: match routes and Django reverse() in linear time, and refuse ambiguous route paths (#602) - #640
Merged
Merged
Conversation
JuroOravec
force-pushed
the
fix/602-segment-route-matcher
branch
from
November 14, 2026 13:37
854b704 to
89f7471
Compare
… with Citry's matcher (#602) Every adapter now matches request paths with Citry's own segment matcher; the regex from compile_route_pattern is kept only for Django's reverse() and URL checks. A route whose full path puts two parameters side by side (`{a}{b}`, in one path or across a parent and child) or repeats a parameter name raises ValueError naming the route(s) when asgi_app(), wsgi_app(), the Flask and FastAPI mount(), or Django's urlpatterns() mount the routes. Other routes match the same paths with the same values. Two quick split paths (a search from the right, and a split at each `.` for Citry's cache-route shape) keep matching fast; the general walk serves the remaining dotless mixes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ck dotless_params type (#602) The regex the Django integration keeps for each Citry route now puts each parameter in an atomic group that stops at the first place the following text can start, so reverse() searches the URL it builds in time in step with its length. One converter per parameter checks the URL with Citry's own matcher, reading all of the call's values from reverse() itself, so reverse() keeps returning the URLs it returned before. URLRoute now raises TypeError when dotless_params is not a frozenset of parameter names. compile_route_pattern is removed; tests keep the earlier regex as a reference in tests/_route_oracle.py. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… Django's frame (#602) The converter for each Citry route parameter now refuses a value that is empty, holds a `/`, or holds a `.` for a dotless parameter, and keeps no state and reads nothing from Django's internals. With every value passing, the values themselves are a split the route accepts, so the linear regex accepts the URL and reverse() returns the URL it returned before. Other values now raise NoReverseMatch, where the earlier regex could return a URL that the route splits into different values. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
fix/602-segment-route-matcher
branch
from
November 14, 2026 13:38
89f7471 to
d7d2ee1
Compare
JuroOravec
added a commit
that referenced
this pull request
Nov 14, 2026
…ight merged changes (#682) Add one record under docs/security/reviews/ for each of the eight published 0.8.0 advisories (GHSA-4hj5, -8xvf, -7qpw, -g658, -x6rm, -h524, -xmx5, -xg8c) and for each of the pull requests that Mechanism 7, step 7 owes one: #610, #640, #651, #652, #653, #658, #674 and #675. Each record says only what the public pull request, the published advisory, the merged code and its tests show, and lists what was not checked. The reviews README describes how a record for a published advisory differs from a pull request record. The Mechanism 7 list in CLAUDE.md gains the two places that GHSA-7qpw added: parser rules browsers differ on, and the page's declared encoding. Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Closes #602.
Citry now matches every request path against its routes with its own segment matcher, in every web framework integration, and Django's
reverse()on Citry routes takes time in step with the length of the values. Both are stricter about route paths and values that have no single meaning.What changes for apps
URLRoutepath such as"{year}{month}", or a parent path ending in a parameter joined to a child path starting with one ("files/{name}"+"{ext}"), raisesValueErrornaming the route (both routes for a parent and child) whenasgi_app(),wsgi_app(), the Flask or FastAPImount(), or Django'surlpatterns()mounts the routes. Before, such a route matched and the first parameter took all but the last character."{id}/{id}") raisesValueErrorat mount instead of a regular expression error later.dotless_paramsmust be afrozensetof names; anything else raisesTypeErrorwhen theURLRouteis built.reverse()raisesNoReverseMatchfor a value that is empty, holds a/, or holds a.for a dotless parameter. Before, it could return a URL that the route splits into different values (cache/a.b.jsforclass_id="a.b"). Every other call returns the same URL as before.How it works
util/routing.py: one cached parser splits a full route path into segments and refuses repeated or adjacent parameters.check_route_table()checks every handler route's full path at mount. The matcher splits a segment with a search from the right, a split at each.(Citry's cache routes), or a general walk for other dotless mixes; each takes time in step with the segment's length. The regex is no longer used to match requests.contrib/django.py: the pattern class still matches requests with Citry's matcher. Forreverse()it holdsroute_reverse_regex(), where each parameter is an atomic group that stops at the first place the following text can start, plus one converter per parameter that refuses a value the route could never give back. When every value passes, the values are a split the route accepts, so the regex accepts the URL.URLRoutedocstring, the "Serve extension routes" section (new "Stop a value at a dot" and "Separate two parameters" subsections),Raises:text on the adapters, and two design-doc lines. Changelog under Unreleased with an upgrade note.Tests
tests/test_route_pattern_linear.py: the matcher against the earlier regex (tests/_route_oracle.py) on generated routes, refusal messages,dotless_paramsrules and type, and growth tests that compare an input with one eight times as long.tests/test_route_path_rules.py: every adapter refuses an adjacent-parameter route at mount and leaves the app and instance unchanged.tests/test_django_route_reverse.py:reverse()against the earlier regex on generated routes and values (same URL when every value passes, refused otherwise, and the route matches each returned URL), and growth tests forreverse()and for the regex alone.--platform linux) are clean.Review
Independent reviews covered the matcher, the mount checks, the Django
reverse()change, the security pass for request routing and URL building, and a separate prose pass. One case is recorded as unproven: an author-written parentre_paththat refuses its own text but matches a longer prefix reaching into the Citry part.🤖 Generated with Claude Code