Fix routing of percent-encodable fixed path segments - #13459
Draft
silentiris wants to merge 2 commits into
Draft
Conversation
DynamicResource and PrefixResource percent-encoded fixed path segments at registration time and used the encoded form for both the regex pattern and the resource index key. The resolver walks the decoded path (path_safe), so the encoded index key was never probed and the resource was never a candidate — every request to such a route returned 404. Use the decoded form for the regex pattern, the canonical property, and the stored prefix so they match the decoded path_safe. Keep the encoded form for the formatter and url_for() so generated URLs remain valid. Fixes aio-libs#13433
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #13459 +/- ##
==========================================
+ Coverage 98.42% 99.00% +0.58%
==========================================
Files 133 132 -1
Lines 49747 49651 -96
Branches 2628 2575 -53
==========================================
+ Hits 48961 49157 +196
+ Misses 662 370 -292
Partials 124 124
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
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 do these changes do?
Fixes #13433
Dynamic routes (and static/prefix resources) whose fixed path segment contains characters that need percent-encoding — a space, non-ASCII, or some reserved characters — were unreachable: every request to them returned 404, and the URL produced by
url_for()could not be routed back either.Root cause:
DynamicResource.__init__percent-encoded fixed parts with_requote_path()and used the encoded form for both the regex pattern and the resource index key.PrefixResource.__init__did the same with the prefix. ButUrlDispatcher.resolvewalks the decodedrequest.rel_url.path_safebackwards to find candidates. The encoded index key was never probed, so the resource was never a candidate. Even if it had been, the encoded regex pattern would not have matched the decoded path.Fix:
DynamicResource: use decoded fixed parts for the regex pattern and thecanonicalproperty (which feeds the resource index key); keep the encoded form in the formatter sourl_for()still produces valid encoded URLs.PrefixResource: store the decoded prefix (used byStaticResource.resolvefor prefix matching and bycanonicalfor the index key);StaticResource.url_fornow encodes the prefix on the fly.Are there changes in behavior for the user?
Routes with spaces or non-ASCII characters in fixed path segments (e.g.
/hello world/{name}or/static files/) are now correctly resolvable. Previously they returned 404.url_for()output is unchanged — it still produces properly percent-encoded URLs.Is it a substantial burden for the maintainers to support?
No. The fix is a small, well-contained change in
web_urldispatcher.pywith three focused regression tests. No new dependencies, no configuration changes, no API changes.Related issue number
Fixes #13433
Checklist
CONTRIBUTORS.txtCHANGES/folderTest results
Drafted with Claude Code; reviewed by silentiris.