Skip to content

Commit 7fcb3eb

Browse files
committed
fix(isRgbColor): allow arbitrary decimal digits for alpha values and trailing zeros on 1
1 parent a38f15b commit 7fcb3eb

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/lib/isRgbColor.js

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

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

1010
export default function isRgbColor(str, options) {

test/validators.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5122,6 +5122,10 @@ describe('Validators', () => {
51225122
'rgb(5%,5%,5%)',
51235123
'rgba(5%,5%,5%,.3)',
51245124
'rgba(5%,5%,5%,.32)',
5125+
'rgba(255,255,255,.123)',
5126+
'rgba(5%,5%,5%,.321)',
5127+
'rgba(0,0,0,1.00)',
5128+
'rgba(0,0,0,0.12345)',
51255129
],
51265130
invalid: [
51275131
'rgb(0,0,0,)',
@@ -5130,12 +5134,10 @@ describe('Validators', () => {
51305134
'rgb()',
51315135
'rgba(0,0,0)',
51325136
'rgba(255,255,255,2)',
5133-
'rgba(255,255,255,.123)',
51345137
'rgba(255,255,256,0.1)',
51355138
'rgb(4,4,5%)',
51365139
'rgba(5%,5%,5%)',
51375140
'rgba(3,3,3%,.3)',
5138-
'rgba(5%,5%,5%,.321)',
51395141
'rgb(101%,101%,101%)',
51405142
'rgba(3%,3%,101%,0.3)',
51415143
'rgb(101%,101%,101%) additional invalid string part',

0 commit comments

Comments
 (0)