Skip to content

Escape special characters in CSS class selectors#4

Merged
Artmann merged 1 commit into
mainfrom
claude/fix-css-parser-escaping-l8i0I
Apr 19, 2026
Merged

Escape special characters in CSS class selectors#4
Artmann merged 1 commit into
mainfrom
claude/fix-css-parser-escaping-l8i0I

Conversation

@Artmann
Copy link
Copy Markdown
Owner

@Artmann Artmann commented Apr 19, 2026

Summary

This PR adds CSS identifier escaping to the Breeze template compiler to properly handle special characters in configuration keys when generating CSS class selectors.

Key Changes

  • New CssEscape utility class: Implements Identifier() method that escapes special characters (forward slashes, periods, colons, percent signs, etc.) in CSS identifiers by prefixing them with backslashes, while preserving valid CSS characters (letters, digits, hyphens, underscores)
  • Handlebars helper registration: Registers a cssEscape helper in the Compiler static constructor to make the escaping function available in Handlebars templates
  • Template updates: Applied cssEscape helper to all 40+ CSS class selector generation points in the template (backgrounds, borders, spacing, sizing, typography, etc.)
  • Comprehensive test coverage: Added CssEscapeTests class with 6 test cases covering forward slashes, periods, colons, percent signs, and edge cases
  • Integration test: Added test in CompilerTests to verify that special characters in configuration keys are properly escaped in the compiled CSS output

Implementation Details

The CssEscape.Identifier() method iterates through each character and escapes any character that isn't alphanumeric, a hyphen, or an underscore. This ensures that configuration keys like "1/2", "0.5", and "hover:50%" generate valid CSS selectors like .basis-1\/2, .p-0\.5, and .hover\:50\% respectively.

https://claude.ai/code/session_01Ub9WMzEk9DBUZxnrSMktLd

Newer Unity USS parsers reject unescaped '.' and '/' in class selectors
(e.g. .basis-1/2, .p-0.5). Add a CssEscape helper, register it as a
Handlebars helper, and use it for every selector key in template.hbs so
the generated output emits .basis-1\/2, .p-0\.5, etc.

https://claude.ai/code/session_01Ub9WMzEk9DBUZxnrSMktLd
@Artmann Artmann merged commit f148681 into main Apr 19, 2026
2 checks passed
@Artmann Artmann deleted the claude/fix-css-parser-escaping-l8i0I branch April 19, 2026 10:21
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.

2 participants