fix: decode percent-encoded filenames before asset URL rewrite - #38962
Open
Waleed-Mujahid wants to merge 1 commit into
Open
fix: decode percent-encoded filenames before asset URL rewrite#38962Waleed-Mujahid wants to merge 1 commit into
Waleed-Mujahid wants to merge 1 commit into
Conversation
Waleed-Mujahid
force-pushed
the
fix/static-replace-unicode-double-encoding-upstream
branch
from
August 7, 2026 05:34
ea2ab71 to
3ebc438
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.
Description
When an HTML component contains an asset URL with a percent-encoded unicode filename — e.g. an image named
Se_protéger.pngwhich TinyMCE encodes as/static/Se_prot%C3%A9ger.png— thereplace_static_urlspipeline double-encodes it into a broken URL.Root cause:
replace_static_urlpasses the rawrestcapture group (already percent-encoded by the browser/editor) directly intoStaticContent.get_canonicalized_asset_path(), which internally callsquote_plus. That re-encodes the literal%character, turning%C3%A9→%25C3%25A9. The resulting asset URL does not match the stored asset key and returns a 404.Fix: Call
urllib.parse.unquote(rest)before building the asset key, so the filename is decoded once to its raw unicode form (é) and then re-encoded cleanly once byget_canonicalized_asset_path.unquote(notunquote_plus) is intentional —+must remain a literal+in asset paths, not be decoded to a space.The fix is scoped to the Mongo-backed asset branch of
replace_static_urland does not affect the staticfiles lookup path.Supporting information
unquoteis a no-op on input that contains no percent-encoded sequences).Testing
Unit test added:
test_replace_static_url_with_percent_encoded_unicode<img src="/static/Se_prot%C3%A9ger.png" />%25C3%25A9is absent from the output (no double-encoding)get_canonicalized_asset_pathis called with the decoded filenameSe_protéger.png