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

[cssom-1] Trim the name argument CSSStyleDeclaration.setProperty() #11418

Open
cdoublev opened this issue Dec 27, 2024 · 2 comments
Open

[cssom-1] Trim the name argument CSSStyleDeclaration.setProperty() #11418

cdoublev opened this issue Dec 27, 2024 · 2 comments
Labels
cssom-1 Current Work

Comments

@cdoublev
Copy link
Collaborator

This would also apply to CSSStyleDeclaration.getPropertyValue(), and possibly CSSStyleValue.parse() and CSSFontFeatureValuesMap.*().

For CSSStyleDeclaration and CSSStyleValue, when name is not a custom property name, it is normalized to lowercase. I feel like it should be trimmed too: style.setProperty(' /**/ color', 'green') would be valid. It is currently invalid in all browsers (with or without the comment). There is no correspond test on WPT.

Trimming whitespaces/comments is consistent with the CSS parser entry points (and algorithms). They are either ignored or trimmed in value (style.setProperty('color', ' /**/ green ') is valid), CSSStyleSheet.insertRule(), CSSStyleSheet.replace*(), MediaList.appendMedium(), etc.

@cdoublev cdoublev added the cssom-1 Current Work label Dec 27, 2024
@Loirooriol
Copy link
Contributor

The API expects the raw property name, not a CSS value.

For example, .setProperty("--a b", value) sets the --a b property, which in CSS you would need to escape with something like --a\ b: value.

And of course this is not just for setProperty, the item() indexing returns the raw name, getPropertyValue expects the raw name, etc. Parsing/serializing some of them as CSS values but not others would just break things.

And I don't really see the benefit of changing them all.

@cdoublev
Copy link
Collaborator Author

cdoublev commented Dec 27, 2024

Ah ok, thanks for letting me know about this.

I see this test for that on WPT. So this similar to CSSKeyframesRule.name then, which is inconsistent with CSSCounterStyleRule.name by the way: browsers parse its input as a CSS value, against <counter-style-name>.

Is it normal that this is not clearly specified? Eg. with "when name is a custom property name, replace name with CSS.escape(name).

Now this does not prevent trimming whitespaces and comments. There is no benefit, except consistency:

style.setProperty(' /**/ color /**/ ', 'green') // invalid
style.cssText = ' /**/ color /**/ : green' // valid
style.setProperty('color', ' /**/ green /**/ ') // valid
styleSheet.insertRule(' /**/ style {} /**/ ') // valid
styleSheet.media.appendMedium(' /**/ (width: 1px) /**/ ') // valid

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

No branches or pull requests

2 participants