Skip to content

Commit

Permalink
isRgbColor no longer ignores spacing between rgba? at start
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h-i committed Aug 16, 2022
1 parent 34c45ec commit 69183fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/isRgbColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const rgbColor = /^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}
const rgbaColor = /^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/;
const rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/;
const rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;
const startsWithRgb = /^rgba?/;

export default function isRgbColor(str, includePercentValues = true) {
assertString(str);
Expand All @@ -14,8 +15,8 @@ export default function isRgbColor(str, includePercentValues = true) {
return rgbColor.test(strippedStr) || rgbaColor.test(strippedStr);
}

return rgbColor.test(strippedStr) ||
return startsWithRgb.test(str) && (rgbColor.test(strippedStr) ||
rgbaColor.test(strippedStr) ||
rgbColorPercent.test(strippedStr) ||
rgbaColorPercent.test(strippedStr);
rgbaColorPercent.test(strippedStr));
}
3 changes: 3 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -4278,6 +4278,7 @@ describe('Validators', () => {
'rgba(5%,5%,5%,.3)',
'rgb( 255,255 ,255)',
'rgba(255, 255, 255, 0.5)',
'rgba(255, 255, 255, 0.5)',
],
invalid: [
'rgb(0,0,0,)',
Expand All @@ -4293,6 +4294,8 @@ describe('Validators', () => {
'rgba(3,3,3%,.3)',
'rgb(101%,101%,101%)',
'rgba(3%,3%,101%,0.3)',
'r g b( 0, 251, 222 )',
'r g ba( 0, 251, 222 )',
],
});

Expand Down

0 comments on commit 69183fe

Please sign in to comment.