Skip to content

Commit b2a999d

Browse files
authored
fix(isRgbColor): fix validation of rgb(a) ColorPercentage strings (#2114)
fixes #2113 related to #2113
1 parent c81df18 commit b2a999d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/lib/isRgbColor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import assertString from './util/assertString';
22

33
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])\)$/;
44
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)?)\)$/;
5-
const rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/;
6-
const rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;
5+
const rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)$/;
6+
const rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/;
77

88
export default function isRgbColor(str, includePercentValues = true) {
99
assertString(str);

test/validators.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4359,6 +4359,8 @@ describe('Validators', () => {
43594359
'rgba(3,3,3%,.3)',
43604360
'rgb(101%,101%,101%)',
43614361
'rgba(3%,3%,101%,0.3)',
4362+
'rgb(101%,101%,101%) additional invalid string part',
4363+
'rgba(3%,3%,101%,0.3) additional invalid string part',
43624364
],
43634365
});
43644366

0 commit comments

Comments
 (0)