Repository navigation
Conversation
dcc.Location reports window.location.pathname, which the browser
percent-encodes. The pages router matched that raw value, so path
variables reached layout() and title() still encoded ("hello%20world")
and pages whose path has spaces or non-ASCII characters fell through to
the 404 page. The server-side meta tags already use the decoded
request.path, so the two disagreed.
Decode the pathname before stripping the prefix and matching it. Also
let a path variable hold a decoded newline: fnmatch already accepts one,
but the regex that extracts the variables did not.
Fixes plotly#2360
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 #2360
dcc.Location gives the pages router
window.location.pathname, which the browser percent-encodes. The router matched that raw value, so:layout()andtitle()still encoded:/report/hello worldgavename="hello%20world"and the tab title "Report hello%20world"paththat has spaces or non-ASCII characters showed the 404 pageThe server-side meta tags already use the decoded
request.path, so on first load og:title said "Report hello world" and then the router changed the tab title to "Report hello%20world".This runs
urllib.parse.unquoteon the pathname in both router callbacks (sync and async) before the prefix is stripped and the page is matched. Query parameters were already decoded byparse_qs, so path variables now behave the same way.Decoding lets a
%0Ain the URL reach_parse_path_variablesas a real newline.fnmatchmatches it, but the regex that pulls out the variables did not (one variable was cut at the newline, two or more raisedIndexError), so that regex now usesre.DOTALL.Behaviour change: apps that already call
unquote()on path variables now decode twice, which only matters for values containing a literal%XX. Apathregistered in encoded form (for example/my%20page) now has to be written decoded.Tested on Windows: the new unit test fails before the change and passes after.
pytest tests/unithas the same 7 Windows-only failures (path separators in the pages tests, andtest_process_server_smoke) with and without the change. I also checked it by hand in Chrome against a local app. I did not run the Selenium integration tests.I used Claude Code to write this change.
Contributor Checklist
optionals
CHANGELOG.md