-
-
Notifications
You must be signed in to change notification settings - Fork 6.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: sanitize asset filenames #9737
Conversation
Ideally the test would test with a .css file too, someone has ideas how to get vite to not bundle-up all css? There is a small chance for differences w rollup if someone were to set a custom sanitizer in rollup options, but that sits in the danger zone, so this fix is still better than leaving asset names unsanitized. |
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.
thanks for figuring this out!!
Needs an additional test for collision resilience |
Collisions are no problem as long as asset hashing isn't turned off. If one would do that, |
with asset hashing disabled,
I think that is still acceptable because not sanitizing asset filenames at all is a larger risk/problem. |
@@ -324,7 +324,7 @@ export function assetFileNamesToFileName( | |||
return hash | |||
|
|||
case '[name]': | |||
return name | |||
return sanitizeFileName(name) |
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.
Shouldn't we use output.sanitizeFileName
here to support custom functions by the user? (and also avoid the need to replicate the default in our code)
https://rollupjs.org/guide/en/#outputsanitizefilename
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.
Discussing with @dominikg in Vite Land, we don't have access to Rollup's default. We can also leave support for custom sanitize functions for another PR. I think we can merge this PR and then work on extending support later.
Description
Vite supplies a custom assetFileName to rollup, which means that rollup itself won't sanitize it further.
This PR copies the default sanitize function from rollup and applies it to the name.
fixes sveltejs/kit#5843
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).