-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Issue with decoding URLs #11138
Fix Issue with decoding URLs #11138
Conversation
🦋 Changeset detectedLatest commit: b242c77 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
// Here we encode the second slash to allow for pattern matching against the second slash. | ||
// The encoded variant can be thought of as a placeholder during this matching process. | ||
// When this process is complete we undo this encoding iff it was applied. | ||
const encodeDoubleSlash = pattern.end && pathname.startsWith("//"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this may seem odd I think it is cleaner then trying to refactor the regular expressions generated by compilePath()
to handle "//"
. This should maintain backwards compatibility support for #8072 in light of the new decoding strategy introduced by this PR. @mjackson I'd appreciate it if you could take a look since you're familiar with this issue and the matching semantics in general.
Thank you for the PR @labkey-nicka! I had actually also been looking into this and had a local branch with some changes that I finally got completed and pushed up in #11199 so I'm going to close this one. I think this approach also had some minor issues with descendant routes and the way we do the |
Rationale
This addresses #10814 by switching from using
safelyDecodeURI()
to usingsafelyDecodeURIComponent()
inmatchRoutes()
. The reason usingdecodeURIComponent
is necessary is because it does not assume is is operating on a full URI. From MDN:The result is when
decodeURI
it can lead to portions of the string not being decoded properly.Example
This example shows what is currently happening when
decodeURI
is used and is borrowed from #11109:Then navigate to the following URL:
/bad%20%26%20encoding%20%25%20here
Expected: The parameter should be decoded and
"bad & encoding % here"
is logged.Actual: The parameter is not decoded properly and
"bad %26 encoding % here"
is logged.This PR fixes this and adds regression tests.
Changes
matchRoutes()
utility to usesafelyDecodeURIComponent()
.pathname
once rather than per call tomatchRouteBranch
as thepathname
does not change.safelyDecodeURIComponent
to optionally take theparamName
argument.safelyDecodeURI
as this utility is no longer used. Happy to walk this back if the maintainers feel different about leaving code like this around.