Skip to content

Recognize ASCII case-insensitive color function names - #579

Open
Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
microsoft:mainfrom
pradeep-ramola:fix/case-insensitive-color-functions
Open

Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
microsoft:mainfrom
pradeep-ramola:fix/case-insensitive-color-functions

Conversation

@pradeep-ramola

Copy link
Copy Markdown
Contributor

Problem

Valid uppercase and mixed-case CSS color functions are not reported by findDocumentColors. For example, .test { color: RGB(34, 89, 234); } returns no colors, while the lowercase spelling works.

Function identifiers retain their source casing in the AST, but getColorValue compares the name against lowercase strings. The case-insensitive constructor detection therefore disagrees with actual color extraction.

CSS function names are ASCII case-insensitive: https://www.w3.org/TR/css-values-4/#functional-notation

Change

Normalize ASCII uppercase letters in the local function name before dispatching to color conversion. Keep the AST and source ranges unchanged. This also ensures uppercase COLOR() takes the dedicated color-space/alpha path.

The ASCII-only normalization intentionally does not fold the Unicode Kelvin-sign lookalike in o\u212Alab into oklab.

Tests

Added 33 public language-service tests across CSS, LESS, and SCSS:

  • Uppercase and mixed-case spellings of all ten supported function names, compared with lowercase controls.
  • Comma and space syntax, slash alpha, color values, exact source ranges, and original spelling.
  • Malformed/unknown functions and the non-ASCII lookalike remain unrecognized.

Before the production fix: 30 failed, 3 controls passed.

Verification on Windows after a clean npm ci:

  • npm run compile: TypeScript compilation and 7 lint checks passed.
  • Enumerated all 31 compiled test files and ran them with node --enable-source-maps --test: 455 passed, no failures/skips.
  • git diff --check: passed.
  • Supplemental headless Chromium 148 check: five uppercase/mixed-case examples have the same computed color as lowercase, and the Unicode lookalike is rejected.

The compiled files were enumerated explicitly because the npm test script's single-quoted glob does not reliably select tests in this Windows shell. Full VS Code color-decorator UI integration was not run.

AI assistance was used to investigate, implement, test, and draft this contribution.

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