-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
URL encode references to JS files with brackets #1974
Comments
I don't understand what the issue is. It's not clear to me what you're trying to do, but you should URL encode the brackets as others have suggested |
After building the static svelte-kit app, I use the result and serve them using a Java-based web server. That means that the compiled JavaScript files are accessed through Java, which doesn't support brackets in URLs. But that's the way files are accessed through the server, any web server as far as I know. So, brackets in filenames eventually mean brackets in URLs. The files are referenced in the compiled JavaScript using brackets, and that's the problem. How am I supposed to URL encode that? That's still the JavaScript part, where Java does not intervene yet. So, URL encoding does actually help. 👍🏻 But shouldn't the svelte-kit compile workflow generate encoded URLs? I don't know how I am supposed to do it afterwards efficiently. A simple search and replace approach sounds rather dirty to me. |
I figured something out myself, but maybe someone can confirm if this is a sane thing to do. I added the following plugin to {
name: 'java-compatible-import-urls',
renderChunk(code) {
return code.replace(/(import\b.*?)(["'])(.*?)(\2)/g, (match, p1, p2, p3, p4) => {
p3 = p3.replace(/(\[|\])/g, (match, p1) => encodeURIComponent(p1));
return `${p1}${p2}${p3}${p4}`;
});
},
}, This doesn't fix the problem completely, because CSS files are not imported this way 😞 |
It's not super high priority to me since it only happens from Java app servers, so it's one that you'd probably have to track down and send a PR for yourself |
I found another approach using output: {
// adapted from https://github.com/rollup/rollup/blob/master/src/utils/sanitizeFileName.ts
sanitizeFileName(name) {
const match = /^[a-z]:/i.exec(name);
const driveLetter = match ? match[0] : '';
// A `:` is only allowed as part of a windows drive letter (ex: C:\foo)
// Otherwise, avoid them because they can refer to NTFS alternate data streams.
return driveLetter + name.substr(driveLetter.length).replace(/[\0?*:\[\]]/g, '_');
}
} It's a totally different approach as it changes the filenames, but it works like a charm 😄 |
I just ran into this on AWS API Gateway (for someone who's scratching their head). |
Just to mention here (If using Java), Tomcat is not working, while Jetty is working OK with |
Is this still happening? When I |
I can confirm underscores are now present in the output instead of brackets. E.g. |
uhh, where and why is this replacement happening and what would happen if there were |
@dominikg seems like |
I would assume it's happening somewhere in Vite |
I guess this would work if |
Describe the bug
Filenames containing brackets
[]
are allowed on all major file systems, but not in URLs. Files, which are compiled from pages with dynamic parameters, cannot be correctly referenced by JAVA-based frameworks or servers, because they apply RFC3986 very strictly. For more context, see this Stack Overflow comment and this Quarkus issue.Reproduction
Repository: repro-quarkus-sveltekit-badrequest
For reproduction, you will need Java 11.
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
Some bits and pieces are already mentioned in #1149.
The text was updated successfully, but these errors were encountered: