Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/lib/isRgbColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export default function isRgbColor(str, options) {
if (!startsWithRgb.test(str)) {
return false;
}
// strip all whitespace
str = str.replace(/\s/g, '');
// collapse whitespace runs, then drop only the whitespace adjacent to the
// parentheses and commas; whitespace inside a channel/alpha/percent token is
// kept so malformed values such as 'rgb(2 55,0,0)' or 'rgb(25 %,0%,0%)' are
// still rejected. Two linear passes avoid polynomial backtracking (#2885)
str = str.replace(/\s+/g, ' ').replace(/ ?([(),]) ?/g, '$1');
}

if (!includePercentValues) {
Expand Down
4 changes: 4 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5309,11 +5309,15 @@ describe('Validators', () => {
'rgba(255, 255, 255, 0.1)',
'rgb(5% ,5% ,5%)',
'rgba(5%,5%,5%, .3)',
'rgb( 255 , 0 , 0 )',
],
invalid: [
'r g b( 0, 251, 222 )',
'rgb(4,4,5%)',
'rgb(101%,101%,101%)',
'rgb(2 55,0,0)',
'rgba(0,0,0,0. 5)',
'rgb(25 %,0%,0%)',

],
});
Expand Down
Loading