Skip to content
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

Constant CSS values being sanitized #131

Closed
wedow opened this issue Aug 28, 2023 · 1 comment · Fixed by #133
Closed

Constant CSS values being sanitized #131

wedow opened this issue Aug 28, 2023 · 1 comment · Fixed by #133

Comments

@wedow
Copy link

wedow commented Aug 28, 2023

Hey there, thanks for making this great tool!

Playing with porting over some react code and noticed an inconsistency between the docs and CSS generation behaviour. The docs state "Within css blocks, property names, and constant CSS property values are not sanitized or escaped."

But given a CSS expression like

css primaryNav() {
	max-height: calc(100vh - 170px);
	overflow: auto;
}

templ generates

templCSSBuilder.WriteString(`max-height:zTemplUnsafeCSSPropertyValue;`)

Which suggests the max-height value is being sent through safehtml.SanitizeCSS which rejects CSS functions. Is this expected behaviour? Is there a preferred alternative way to express this? I feel I must be overlooking something.

@a-h
Copy link
Owner

a-h commented Aug 28, 2023

Thanks for looking into this, I was able to reproduce the issue easily thanks to your great report. This is a bug - I can't see a reason why a constant value coming from a developer would be sanitized.

It looks like I was overzealous when I added CSS property sanitization to the system, or decided to use the existing sanitization function instead of printing the value, and the existing test suite didn't happen to contain a value that triggered the sanitization, and I didn't use any CSS expressions in my own work with templ so far so you found it first!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants