diff --git a/src/lib/isRgbColor.js b/src/lib/isRgbColor.js index 0229b41c2..c543fe5ec 100644 --- a/src/lib/isRgbColor.js +++ b/src/lib/isRgbColor.js @@ -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); @@ -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)); } diff --git a/test/validators.js b/test/validators.js index d008ee244..08f106b89 100644 --- a/test/validators.js +++ b/test/validators.js @@ -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,)', @@ -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 )', ], });