-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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] decode path only once to fix loading unicode routes #2167
Conversation
🦋 Changeset detectedLatest commit: 50dfe21 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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 |
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.
I think the changes in pnpm-lock.yaml
should be removed in this PR.
done. |
adapter-node
It looks like this is handled inconsistently today. CC @pluvial for We should also figure out how this interacts with I think we should not decode the path in the adapters for the reasons mentioned at expressjs/expressjs.com#1281 (comment). And clearly we don't want to do it twice as we are now. Plus it would be more consistent with Express. Most important is probably that we do it consistently and test and document the expectations. |
@noahsalvi would you be able to update |
Sure 👍 |
btw i thought that the node adapter is using polka. Shouldn't that be the place to look? Or does it not matter due to express and polka sharing the same api? |
Yeah, I just mentioned Express because it is more popular. But I just tested and confirmed that Polka works the same as Express in this manner |
adapter-node
// fall back to an app route | ||
const request = event.request; | ||
const request_url = new URL(request.url); | ||
const parsedURL = new URL(request.url); |
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.
CFW request
doesn't expose the usual props. That's why I did it differently for this adapter. Doc
path: parsed.pathname, | ||
query: parsed.searchParams, | ||
rawBody: body | ||
path: req.path, |
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.
It's not clear to me that this PR is actually changing anything
I just created an index.js
with the source code:
console.log(new URL('http://localhost/über-uns').pathname)
It printed:
/%C3%BCber-uns
If I change the code to console.log(new URL('http://localhost/%C3%BCber-uns').pathname)
it still prints the same thing
So it's actually not clear to me that this PR is changing anything. Am I missing something? Or can you explain what was happening before vs what's happening now?
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.
Well at the moment the render function is receiving, as the path
value, the encoded string /%C3%BCber-uns
.
And now after changing it to take the original path from the req
object without transforming and encoding it with URL class, the value that it receives is /über-uns
I think that the thing you're missing is, that my change for the adapter node, does not wrap the path in a url object, that encodes the string.
Edit:
To observe this, you can clone my repro and modify the server.js file in node_modules to print out req.path and parsed.pathname
Gahhh!!! This is Polka. I tested with |
are you sure that your fix works? Just to clarify, routes with unicode characters work on my computer only when the render function gets a none URI encoded path. Using the polka parser or the URL class to get pathname leads to it not working. await render({
method: req.method,
headers: req.headers, // TODO: what about repeated headers, i.e. string[]
path: '/über-uns' works but '/%C3%BCber-uns' doesn't,
query: parsed.searchParams,
rawBody: body
}); |
Thanks for testing @noahsalvi. I updated the PR and added a new test for |
I just tested it and the test you wrote works, but it does not test the problem that i'm facing. I also tried linking the package to my repro repo and it did not change the outcome. test('route with umlaut returns page', async () => {
const server = await startServer({
render: (incoming) => {
if (incoming.path === '/über-uns') {
return {
status: 200,
body: incoming.path
};
}
}
});
const res = await fetch(`http://localhost:${PORT}/über-uns`);
assert.ok(res.ok);
server.server.close();
}); ^ This would be testing this problem. (Edit: I've added the test to this branch) |
I just tried linking my PR against your repo and it did work You unit test isn't correct. The browser will send an encoded path so you can't check the encoded |
Fixes #2166
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
running check returns this.. but i don't think thats due to my changes
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0