Skip to content

Clamp out-of-range RGB channels in color previews - #585

Open
Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
microsoft:mainfrom
pradeep-ramola:fix/rgb-channel-clamping
Open

Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
microsoft:mainfrom
pradeep-ramola:fix/rgb-channel-clamping

Conversation

@pradeep-ramola

Copy link
Copy Markdown
Contributor

Fixes #584.

Clamp numeric and percentage RGB channels to [0, 1] when producing color previews, as required by CSS Color 4. For example, rgb(300, -20, 0) now produces a red preview instead of no preview.

The existing numeric parser still rejects malformed values. Alpha handling and other color spaces are unchanged; this is independent of #581.

Validation

  • 57 new tests across CSS, SCSS, and Less, covering legacy/modern syntax, each channel boundary, exact preview ranges, malformed values, and in-range controls. Before the fix: 42 failed, 15 passed. After: all passed.
  • TypeScript compilation and all 7 repository lint checks passed.
  • All 481 tests from the current branch passed with explicit compiled test-file enumeration. On this Windows shell, the npm test script's quoted glob discovers zero tests; enumeration avoids that and excludes stale build output from other branches.
  • 48 language-service color comparisons matched Chromium, allowing half an 8-bit channel step for browser serialization rounding. The browser also rejected all three malformed examples.

AI assistance was used to develop and validate this change.

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.

Color previews reject valid out-of-range RGB channels

1 participant