Skip to content

Commit a18d57d

Browse files
contrololWikiRik
andauthored
Allow second digit in rgba alpha value (#2346)
Co-authored-by: Rik Smale <[email protected]>
1 parent 650a2fa commit a18d57d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

1010
export default function isRgbColor(str, options) {

test/validators.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4650,8 +4650,10 @@ describe('Validators', () => {
46504650
'rgba(255,255,255,1)',
46514651
'rgba(255,255,255,.1)',
46524652
'rgba(255,255,255,0.1)',
4653+
'rgba(255,255,255,.12)',
46534654
'rgb(5%,5%,5%)',
46544655
'rgba(5%,5%,5%,.3)',
4656+
'rgba(5%,5%,5%,.32)',
46554657
],
46564658
invalid: [
46574659
'rgb(0,0,0,)',
@@ -4660,11 +4662,12 @@ describe('Validators', () => {
46604662
'rgb()',
46614663
'rgba(0,0,0)',
46624664
'rgba(255,255,255,2)',
4663-
'rgba(255,255,255,.12)',
4665+
'rgba(255,255,255,.123)',
46644666
'rgba(255,255,256,0.1)',
46654667
'rgb(4,4,5%)',
46664668
'rgba(5%,5%,5%)',
46674669
'rgba(3,3,3%,.3)',
4670+
'rgba(5%,5%,5%,.321)',
46684671
'rgb(101%,101%,101%)',
46694672
'rgba(3%,3%,101%,0.3)',
46704673
'rgb(101%,101%,101%) additional invalid string part',

0 commit comments

Comments
 (0)