Skip to content

bug(validation): reject or correctly escape token names that produce invalid CSS identifiers #29

Description

@Hebilicious

Problem

validateName() at 94bf4d8 rejects empty names, periods, value, and selected reserved module names, but accepts whitespace and CSS delimiter characters.

processPrimitives() then interpolates these names directly into the declaration key.

Reproduction

This configuration passes the current name checks:

const config = {
  primitives: {
    "card button": {
      value: {
        default: {
          value: { gap: "1rem" },
        },
      },
    },
  },
};

The current construction produces:

--card button-default-gap: 1rem;

The unescaped space makes this an invalid custom-property declaration name. The result follows directly from the current validator and string construction; add an end-to-end generator/browser regression test.

The same gap applies to other unescaped delimiters that are not excluded by the validator. CSS custom-property names must be valid dashed identifiers; see the specification.

Proposed contract

Choose one explicit policy:

  1. Reject unsupported name segments with a useful configuration-path error; or
  2. Escape names consistently when emitting CSS, while preserving stable configuration paths and references.

Do not silently normalize distinct names into the same generated key. Do not apply identifier restrictions to arbitrary token values, which intentionally contain native CSS expressions.

Acceptance criteria

  • Whitespace and delimiter cases cannot silently generate malformed declaration names.
  • Validation errors identify the offending segment and its configuration path.
  • Valid existing numeric token keys, hyphens, and underscores keep working; define Unicode and escaping behavior deliberately rather than imposing an accidental ASCII-only rule.
  • The emitted key, declaration, reference resolver, and TypeScript/JSON representations agree under the chosen policy.
  • Tests cover primitive names, variants, property names, and other modules that share name validation.
  • Validate generated declaration names with a CSS-aware check; merely parsing a custom-property value is not sufficient.
  • Document compatibility implications and coordinate alias handling with bug(resolver): resolve hyphenated aliases and preserve var() fallback syntax #24.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions