diff --git a/src/lib/isRgbColor.js b/src/lib/isRgbColor.js index 9458522ab..cb52c89e1 100644 --- a/src/lib/isRgbColor.js +++ b/src/lib/isRgbColor.js @@ -1,9 +1,9 @@ import assertString from './util/assertString'; const rgbColor = /^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/; -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 rgbaColor = /^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d\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 rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d\d?|1(\.0)?|0(\.0)?)\)$/; export default function isRgbColor(str, includePercentValues = true) { assertString(str); diff --git a/test/validators.test.js b/test/validators.test.js index 6c68cd71a..0d3d4bd7c 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -4508,8 +4508,10 @@ describe('Validators', () => { 'rgba(255,255,255,1)', 'rgba(255,255,255,.1)', 'rgba(255,255,255,0.1)', + 'rgba(255,255,255,.12)', 'rgb(5%,5%,5%)', 'rgba(5%,5%,5%,.3)', + 'rgba(5%,5%,5%,.32)', ], invalid: [ 'rgb(0,0,0,)', @@ -4518,11 +4520,12 @@ describe('Validators', () => { 'rgb()', 'rgba(0,0,0)', 'rgba(255,255,255,2)', - 'rgba(255,255,255,.12)', + 'rgba(255,255,255,.123)', 'rgba(255,255,256,0.1)', 'rgb(4,4,5%)', 'rgba(5%,5%,5%)', 'rgba(3,3,3%,.3)', + 'rgba(5%,5%,5%,.321)', 'rgb(101%,101%,101%)', 'rgba(3%,3%,101%,0.3)', 'rgb(101%,101%,101%) additional invalid string part',