-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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(encoding): decode params #3350
Merged
Merged
Conversation
This file contains 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
This change forces users to encode their `path` in routes but also fixes existing problems with route location that were provided as string and not encoded. Specially with the slash character, allowing it to be encoded and decoded properly.
Looking forward to merge this at the end of this week |
7 tasks
ttshivers
added a commit
to ttshivers/synclounge-1
that referenced
this pull request
Nov 10, 2020
The parameter encoding is now fixed as of: vuejs/vue-router#3350
ttshivers
added a commit
to ttshivers/synclounge-1
that referenced
this pull request
Nov 10, 2020
The parameter encoding is now fixed as of: vuejs/vue-router#3350
1 task
7 tasks
7 tasks
7 tasks
ttshivers
added a commit
to ttshivers/synclounge-1
that referenced
this pull request
Dec 19, 2020
The parameter encoding is now fixed as of: vuejs/vue-router#3350
ttshivers
added a commit
to ttshivers/synclounge-1
that referenced
this pull request
Jan 17, 2021
The parameter encoding is now fixed as of: vuejs/vue-router#3350
1 task
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 is breaking
Users no longer can use unencoded static paths:
{ path: '/cassé' }
<router-link to="/cassé" />
<router-link :to="{ path '/cassé' }" />
router.push('/cassé')
router.push({ path: '/cassé' })
They have to manually encode them with
encodeURI()
or use a named route:This is only necessary with string locations. When using params and query, the behavior is still the same and using named routes with params is recommended for that reason:
In fact, this PR makes this possible, it wasn't working before.
Similarly, doing
router.push({ name: 'servers', params: { server: 'one/two' }})
will change the url to/servers/one%2Ftwo
while giving the correct value in$route.params.server
.Why this can't be done automatically by the router
We could automatically call
encodeURI()
on each static segment of a path but this would also break code for users who are already correctly encodingpath
(you should always encode URLs, even before this change).How to help the migration
Since we were never supposed to pass an unencoded
path
to a route record or even callrouter.push()
with an unencoded string orpath
property, I propose to warn in dev mode if any unencoded character is passed to help people be aware of how they should encode their routes.Internal explanation
Previously, this used to work because we were decoding paths twice, but this created other problems like errors with URLs containing the character
%
encoded. By fixing this bug we must remove thedecode
call made on the path when matching against existing routes, but this also makes it impossible to automatically encodepath
anymore because the user wouldn't be able to provide encoded characters, e.g. the/
character (%2F
) would be transformed to its encoded version,%252F
(%
is encoded as%25
) and there wouldn't be a way to match an encoded slash character which is necessary in segments of the URL since the slash character is used to differentiate segments in a URL. Without this change, we can't correctly decode%2F
Overall, this makes things consistent and it's also the same behavior that exists in v4
Close #3337
Close #3103
Close #3125