Skip to content

Commit

Permalink
fix(isRgbColor): fix validation of rgb(a) ColorPercentage strings (#2114
Browse files Browse the repository at this point in the history
)

fixes #2113

related to #2113
  • Loading branch information
pano9000 authored Jan 29, 2023
1 parent c81df18 commit b2a999d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/isRgbColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ 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 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 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)?)\)$/;

export default function isRgbColor(str, includePercentValues = true) {
assertString(str);
Expand Down
2 changes: 2 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4359,6 +4359,8 @@ describe('Validators', () => {
'rgba(3,3,3%,.3)',
'rgb(101%,101%,101%)',
'rgba(3%,3%,101%,0.3)',
'rgb(101%,101%,101%) additional invalid string part',
'rgba(3%,3%,101%,0.3) additional invalid string part',
],
});

Expand Down

0 comments on commit b2a999d

Please sign in to comment.