Skip to content
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] handle paths consistently between dev and various production adapters #2171

Merged
merged 2 commits into from
Aug 12, 2021

Conversation

benmccann
Copy link
Member

@benmccann benmccann commented Aug 11, 2021

fixes #2166

dev and adapter-node were passing decoded paths while the other adapters were passing the encoded path sent by the browser

The way to handle the path is to split it on forward slashes and then call decodeURIComponent on each path component. That allows you to handle edge cases like %2f. Luckily, that's what build is currently doing:

function get_params(array) {

Otherwise, we shouldn't touch the path. We should just leave it alone and pass along exactly what we received, which is exactly how Express behaves

Previously there was another bug because we were doing decodeURI followed by decodeURIComponent which would cause each component to be double-decoded. By leaving the path alone we don't run into this issue

@benmccann benmccann added the bug Something isn't working label Aug 11, 2021
@changeset-bot
Copy link

changeset-bot bot commented Aug 11, 2021

🦋 Changeset detected

Latest commit: 64087f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@sveltejs/adapter-node Patch
@sveltejs/kit Patch

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

@benmccann benmccann added this to the 1.0 milestone Aug 11, 2021
@benmccann benmccann added the p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. label Aug 11, 2021
@benmccann benmccann force-pushed the double-decode branch 2 times, most recently from fc6b657 to ff2ef9b Compare August 11, 2021 22:42
@benmccann benmccann changed the title [fix] decode path only once to fix loading unicode routes [fix] handle paths consistently between dev and various production adapters Aug 11, 2021
@benmccann benmccann force-pushed the double-decode branch 4 times, most recently from 35836a0 to c3d0d41 Compare August 12, 2021 04:35
Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally sure I understand the scope of this change. Before, we had this:

image

With this PR, we now have this:

image

Is that intentional?

packages/kit/src/runtime/client/router.js Outdated Show resolved Hide resolved
@benmccann
Copy link
Member Author

Yeah, I think it's the better behavior to return the path as it was received. There are some edge cases that are impossible to handle otherwise. E.g. see this post where Netlify started out giving users the decoded path and had to switch: https://answers.netlify.com/t/bug-fix-url-encoding-preserved-in-function-event/27080. This is also inline with how Express and most other libraries work, so I think it's generally more expected as well

@Rich-Harris Rich-Harris merged commit da94af3 into master Aug 12, 2021
@Rich-Harris Rich-Harris deleted the double-decode branch August 12, 2021 21:51
@Rich-Harris
Copy link
Member

Ah, gotcha. That makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Routes with umlauts are not found in node builds
2 participants