fix(isRgbColor): don't strip whitespace inside values when allowSpaces is true - #2891
Open
yu2971512385-ui wants to merge 1 commit into
Open
yu2971512385-ui wants to merge 1 commit into
yu2971512385-ui wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2891 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2599 2599
Branches 658 658
=========================================
Hits 2599 2599 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…s is true
With `{ allowSpaces: true }` the validator stripped every whitespace character
before testing the numeric patterns, so malformed values whose whitespace fell
*inside* a token were silently accepted: `rgb(2 55,0,0)`, `rgba(0,0,0,0. 5)`
and `rgb(25 %,0%,0%)` all returned true.
Collapse whitespace runs and then drop only the whitespace adjacent to the
parentheses and commas, so whitespace around the comma-separated values (e.g.
`rgb( 255 , 0 , 0 )`) keeps working while whitespace inside a channel/alpha/
percent token now fails validation. The two passes use bounded quantifiers to
avoid polynomial-time backtracking on all-whitespace input.
Fixes validatorjs#2885
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
yu2971512385-ui
force-pushed
the
fix/isRgbColor-inner-whitespace
branch
from
September 17, 2026 03:10
5a079c5 to
f4baeaf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2885.
The bug
With
{ allowSpaces: true },isRgbColorstrips every whitespace character before testing the numeric patterns:That also removes whitespace that falls inside a token, so malformed values are silently accepted:
The fix
Collapse only the whitespace adjacent to the parentheses and commas instead of all whitespace:
Whitespace around the comma-separated values keeps working (
rgb( 255 , 0 , 0 )stays valid), while whitespace inside a channel/alpha/percent token now fails validation as expected. Each channel or alpha value must form a contiguous numeric token and a%must immediately follow its number.Tests
Extended the existing
{ includePercentValues: true, allowSpaces: true }case with the three malformed inputs (now invalid) and a spaced-but-validrgb( 255 , 0 , 0 ). Verified the additions fail on the unpatched source and pass with the fix; fullnpm testis green.Checklist
🤖 Generated with Claude Code