Repository navigation
Fix url_prefix failing to match request path when it contains non-ASCII characters - #508
Open
cristianchiriac wants to merge 2 commits into
Open
cristianchiriac wants to merge 2 commits into
cristianchiriac wants to merge 2 commits into
Conversation
The request path is decoded from raw bytes as "UTF-8 bytes read as
latin-1", following the WSGI convention for PATH_INFO/SCRIPT_NAME (see
uri.decode("latin-1") in parser.py). url_prefix was left as the plain
unicode string passed in configuration, so comparing it against the
path in task.py's get_environment() never matched once url_prefix
contained a non-ASCII character, and SCRIPT_NAME/PATH_INFO were never
split correctly.
Apply the same UTF-8-as-latin-1 re-encoding to url_prefix at
configuration time, in slash_fixed_str(), so it lines up with the path
it's compared against.
Fixes Pylons#492
Author
|
Hi! Gentle ping on this fix. It's ready for review whenever you have a moment, and I'm happy to make any changes you'd like. Thanks! |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ce8Hr56xHurqiV5wEkVmxj
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.
Fixes #492.
Bug
url_prefixfails to match the request path whenever it contains a character outside ASCII. The request path is decoded inparser.pyasuri.decode("latin-1"), i.e. the raw UTF-8 bytes read back as latin-1 (the usual WSGI trick for carrying arbitrary bytes throughstr).url_prefix, on the other hand, is stored as whatever unicode string was passed in configuration, with no equivalent re-encoding.task.py'sget_environment()then compares the two directly, so aurl_prefixwith non-ASCII characters never matches the corresponding (differently-encoded) path, andSCRIPT_NAME/PATH_INFOnever get split correctly for it.Fix
slash_fixed_str()inadjustments.py(used only for normalizingurl_prefix) now re-encodes the string as UTF-8 bytes decoded as latin-1 after the existing slash normalization, matching the encoding the path comparison intask.pyexpects.Test plan
test_url_prefix_non_asciitoTestAdjustmentsintests/test_adjustments.py, checking that a non-ASCIIurl_prefixcomes out re-encoded to match the path's encoding convention.pytest tests/: 669 passed, 70 skipped (skips are pre-existing, unrelated to this change).black --checkandisort --check-onlyon the changed files: clean.