-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 url for middleware #4728
Conversation
Co-authored-by: CHOYSEN <[email protected]>
Co-authored-by: Shinigami <[email protected]>
Co-authored-by: Jeff Yang <[email protected]>
This middleware is copied from the old commits, I should check it first 😓 |
pinging @benmccann so it is aware of this @hannoeru do you think we could add a test case to avoid future regressions? |
This isn't the right fix. URLs should not be globally decoded in middleware. The
Rather than decode the request URL globally in middleware, each consumer should decode as necessary if required for their use case. I'm fairly confident that I don't see any description of what bug is being hit, how to reproduce it, etc. I would guess that if anything needs to be changed it's something in Vite itself that should decode the URL just in that middleware and not globally |
Currently, if you serving files that using Unicode filename it will fail in transform middleware because it can't resolve to a correct path in the filesystem. I just checked express's source code, decode URL inside middleware is the normal way to do it so I will change it. About |
That's exactly the opposite of what that pull request does 😄 The PR description is: "do not decode
The second parameter to |
But parse only take one argument https://github.com/lukeed/polka/blob/master/packages/url/index.js, why 🧐 |
and there it has two arguments: https://github.com/lukeed/polka/blob/e0a65c781b763f7421f1a64d4166b3911f4d20e9/packages/url/index.js#L20 |
Got it, thank you for the clarification, I will make some changes. |
@benmccann Just add some test than I found that |
Ok. I would say let's see if we can get Thanks for tracking down the issue @hannoeru ! |
just published |
@lukeed that didn't work because The first time it will set Maybe we can use another variable like |
That's...odd. Performs great I'm sure 😮💨 I left a TODO for myself to improve this later, but guess I'll do it now. |
Then you'll still need your cleanup after all. Decoding is expensive and needs to be prevented as much as possible. There's no other sane/reliable way to cache this value per request lifecycle, and arguably passing the same request thru the same middleware but with different urls is out of the ordinary. I don't know how connect works, but a core thing Polka/Express does is make sure that any The only thing I can do on my site is remove decoding from let pathname = decodeURIComponent(req.path || parser(req)); I'd have to check dependents and see how inconvenient this may be for them. |
Wow, just one sleep and these comments going wild (in a positive way 😃) |
…hange url in middleware
I just changed to cleanup |
Just to clarify – this isn't an upstream bug. This has to do with how vite is manually juggling & manipulating |
… decoded url when url changed
Sorry, I'm back 🙃 Turns out, no one else cared about the built-in decoding in the URL parser, so I removed it & implemented it manually in sirv. I also removed any reliance on previous values, so the These changes are now available as |
Thanks for implementing this tweak in sirv so fast @lukeed! @hannoeru I think it is a good idea to use |
Co-authored-by: CHOYSEN <[email protected]> Co-authored-by: Shinigami <[email protected]> Co-authored-by: Jeff Yang <[email protected]>
Description
#4600 deletes decode URL middleware because decode will be processed by
sirv
, but we still need to decode URL fortransform middleware.
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).