Skip to content

fix: Validate malformed CSS variable values#5787

Merged
kof merged 1 commit into
mainfrom
fix-css-variable-value-validation
Jun 1, 2026
Merged

fix: Validate malformed CSS variable values#5787
kof merged 1 commit into
mainfrom
fix-css-variable-value-validation

Conversation

@kof
Copy link
Copy Markdown
Member

@kof kof commented Jun 1, 2026

Summary

Validates CSS custom property values as raw CSS token streams before saving/parsing them.

This prevents malformed values like #sd' from being normalized into sd or serialized into broken canvas CSS that invalidates the whole generated rule.

Changes

  • Added tokenizer-based validation for custom property values.
  • Rejects malformed strings, URLs, comments, unmatched blocks, and trailing backslashes.
  • Preserves raw custom property declaration values before css-tree can repair/normalize them.
  • Prevents custom property value editing from coercing invalid input through fallback parsing like kebabCase() or color recovery.
  • Added regression tests for advanced panel input and CSS data parsing.

Verification

  • pnpm --filter @webstudio-is/css-data test -- parse-css-value.test.ts parse-css.test.ts
  • pnpm --filter @webstudio-is/builder test -- parse-intermediate-or-invalid-value.test.ts parse-style-input.test.ts

@kof kof force-pushed the fix-css-variable-value-validation branch from 6747859 to 61ce1d3 Compare June 1, 2026 14:48
@kof kof merged commit 95dc7f0 into main Jun 1, 2026
20 of 22 checks passed
@kof kof deleted the fix-css-variable-value-validation branch June 1, 2026 15:03
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 this pull request may close these issues.

1 participant