浏览代码

RGBA color value RegExp should accept 0 as alpha.

Maciej Gołaszewski 5 年之前
父节点
当前提交
e62c9186d7

+ 3 - 3
packages/ckeditor5-engine/src/view/styles/utils.js

@@ -9,9 +9,9 @@
 
 const HEX_COLOR_REGEXP = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
 const RGB_COLOR_REGEXP = /^rgb\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}[0-9]{1,3}[ %]?\)$/i;
-const RGBA_COLOR_REGEXP = /^rgba\([ ]?([0-9]{1,3}[ %]?,[ ]?){3}(1|[0-9]+%|[0]?\.[0-9]+)\)$/i;
-const HSL_COLOR_REGEXP = /^hsl\([ ]?([0-9]{1,3}[ %]?[,]?[ ]*){3}(1|[0-9]+%|[0]?\.[0-9]+)?\)$/i;
-const HSLA_COLOR_REGEXP = /^hsla\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}(1|[0-9]+%|[0]?\.[0-9]+)\)$/i;
+const RGBA_COLOR_REGEXP = /^rgba\([ ]?([0-9]{1,3}[ %]?,[ ]?){3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i;
+const HSL_COLOR_REGEXP = /^hsl\([ ]?([0-9]{1,3}[ %]?[,]?[ ]*){3}(1|[0-9]+%|[0]?\.?[0-9]+)?\)$/i;
+const HSLA_COLOR_REGEXP = /^hsla\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i;
 
 const COLOR_NAMES = new Set( [
 	// CSS Level 1

+ 26 - 2
packages/ckeditor5-engine/tests/view/styles/utils.js

@@ -61,12 +61,36 @@ describe( 'Styles utils', () => {
 				'rgb(11, 22, 33, 0.1)',
 				'rgb(11, 22, 33, .153)'
 				// Unsupported:
-				// 'rgb(100%, 0, 60%)', // Mixed numbers and percentages. TODO: might be skipped - adds complexity.,
+				// 'rgb(100%, 0, 60%)', // Mixed numbers and percentages - adds complexity.,
 			], value => !isColor( value ) );
 		} );
 
 		it( 'returns true for rgba() color', () => {
-			testValues( [ 'rgba(1,2,3,0.7)', 'rgba(12%,0,0,1)' ], isColor );
+			testValues( [
+				'rgba(1,2,3,0.7)',
+				'rgba(12%,0,0,1)',
+				'rgba(255,0,153, 0.123)',
+				'rgba(255, 0, 153, 0.123)',
+				'rgba(100%,0%,60%, 0.123)',
+				'rgba(100%, 0%, 60%, 0.123)',
+				'rgba(255,0,153, 0)',
+				'rgba(255, 0, 153, 0)',
+				'rgba(100%,0%,60%, 0)',
+				'rgba(100%, 0%, 60%, 0)',
+				'rgba(255,0,153, 1)',
+				'rgba(255, 0, 153, 1)',
+				'rgba(100%,0%,60%, 1)',
+				'rgba(100%, 0%, 60%, 1)'
+			], isColor );
+		} );
+
+		it( 'returns false for wrong rgba() color', () => {
+			testValues( [
+				'rgba(1,2,3,0.7',
+				'rgba((1,2,3,0.7',
+				'rgba(1,a,3,0.7)',
+				'rgba(1,2,3,*)',
+			], value => !isColor( value ) );
 		} );
 
 		it( 'returns true for hsl() color', () => {