-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
cssHash's hash() function may generate invalid CSS identifiers #6821
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
Comments
You are correct, but the right way to use it is. compilerOptions: {
cssHash: ({ hash, css }) => `custom-${hash(css)}`,
}, |
I'm well aware how it's supposed to be used. This is a quick POC to prove Svelte does not escape problematic identifiers (howsoever arising). |
The hash function provided is implemented with the assumption that it's output will be prefixed in order to turn the hash into a valid css class name. If you want a truly custom solution, you could very easily substitute the hash function for some other hashing function that guarantees that it's output will always be a valid css class name. |
https://mathiasbynens.be/notes/css-escapes Escaping CSS identifiers is a bit of a pain. If someone wants to implement that, great. Another viable option might be to have the compiler throw an exception when the value returned by your |
https://github.com/mathiasbynens/cssesc looks like a nice, small, self-contained library for this CSS identifier escaping. If we want to use that to do the escaping, that sounds fine to me. |
Alternatively we could renamed |
Describe the bug
cssHash: ({hash}) => hash('foo'),
returns2nhsez
, which is an invalid CSS identifier since it starts with a number, unless the identifier is escaped, which Svelte does not do.Reproduction
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: