-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Escape characters not allowed by URL specs but not escaped by URL::toString
#10307
Comments
Summary of what was discussed in the above issueThe "[" in the path part is not allowed in RFC 3986 (successor to RFC 2396), but is allowed in the URL Standard. Both Node.js and browsers parses relative import specifiers in compliance with the URL Standard. So this is a valid JS in both browser and Node.js. However, the Java server used rejects this URL because it is compliant with RFC3986, not the URL Standard. |
Umm, rereading the URL Standard spec, it seems I'm wrong. Because
related: whatwg/url#379, whatwg/url#753 |
URL::toString
Hey, it seems like I got here by the same path as you (Java proxy in dev mode lol). Any idea what should be changed to fix this? 😄 |
Ok... This is impossible to solve outside of Vite. The only way I see this ever being fixed is by providing a plugin pair in Vite that decodes all URLs and then encodes them at the end of the build. This cannot come from user land, because import analysis runs in post and encoding breaks that plugin. Something like this: const decodingPlugin = {
name: 'decode-imports',
transform(code, id, options) {
// ... run only on csr and javascirpt files
const staticImportRE = /^\s*import\s+(?:[\w*{}\s,]*\s+from\s+)?['"]([^'"]%[^'"])['"]\s*;?\s*$/
return {
code: code.replaceAll(staticImportRE, (match, importUrl) => {
return match.replace(importUrl, decodeURI(importUrl))
})
}
},
enforce: 'pre'
}, |
Describe the bug
Whe using vite in dev mode behind a proxy illegal characters in URL can lead to errors.
As an example Nuxt 3 uses [foo] as pattern for dynamic routes. During development url for modules aren't properly url-encoded.
Reproduction:
open stackblitz example and navigate to /test/id. In the browser network trace there is a request for /test/[id].vue which fails when used behind certain proxies.
nuxt/nuxt#15049
Reproduction
https://stackblitz.com/edit/github-tjxq2a-k3p4ab
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: