From e7947408616f68e3d76e94b64687e81b1a327396 Mon Sep 17 00:00:00 2001 From: nyteksf Date: Mon, 5 Feb 2018 15:00:19 -0800 Subject: [PATCH 1/7] Modified isValid() to discrimate against improperly formatted color objects --- tinycolor.js | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 9580299..9b26463 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -303,15 +303,24 @@ tinycolor.fromRatio = function(color, opts) { // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" // function inputToRGB(color) { - + var rgb = { r: 0, g: 0, b: 0 }; var a = 1; var s = null; var v = null; var l = null; var ok = false; + var tooManyCommas = false; var format = false; + /* Add check for proper comma usage */ + var colorSplitToArray = "" + color.split(","); + for(let i=0, len=colorSplitToArray.length; i 360 || color.s < 0 || color.s > 100 || color.l < 0 || color.l > 100) { + ok = false; /* value out of bounds */ + } else { + ok = true; /* valid range used */ + } s = convertToPercentage(color.s); l = convertToPercentage(color.l); rgb = hslToRgb(color.h, s, l); - ok = true; format = "hsl"; } + /* Add validation of color.a values */ if (color.hasOwnProperty("a")) { + if (format === "hsl" && color.a > 1 || color.a < 0) { + ok = false; + } a = color.a; } + if (tooManyCommas) ok = false; /* If false, format invalid */ } - + a = boundAlpha(a); return { @@ -1050,21 +1074,30 @@ function convertHexToDecimal(h) { var matchers = (function() { + + // var CSS_INTEGER = "[-\\+]?\\d+%?"; - + + + // var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?"; + + // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome. var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")"; + // Actual matching. // Parentheses and commas are optional, but not required. // Whitespace can take the place of commas or opening paren var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; + + var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; - + return { CSS_UNIT: new RegExp(CSS_UNIT), rgb: new RegExp("rgb" + PERMISSIVE_MATCH3), From 77fecb459242b47afc579765a5823cd8b1160f06 Mon Sep 17 00:00:00 2001 From: nyteksf Date: Mon, 5 Feb 2018 15:02:08 -0800 Subject: [PATCH 2/7] Fixed whitespace issue --- tinycolor.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tinycolor.js b/tinycolor.js index 9b26463..2c0e2a7 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -303,7 +303,6 @@ tinycolor.fromRatio = function(color, opts) { // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" // function inputToRGB(color) { - var rgb = { r: 0, g: 0, b: 0 }; var a = 1; var s = null; From 95ca0c31699f1510169b08abedf1d806d9073468 Mon Sep 17 00:00:00 2001 From: nyteksf Date: Mon, 5 Feb 2018 15:05:30 -0800 Subject: [PATCH 3/7] Adjust format --- tinycolor.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 2c0e2a7..58de217 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -1074,27 +1074,21 @@ function convertHexToDecimal(h) { var matchers = (function() { - + // var CSS_INTEGER = "[-\\+]?\\d+%?"; - - // var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?"; - - // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome. var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")"; - // Actual matching. // Parentheses and commas are optional, but not required. // Whitespace can take the place of commas or opening paren var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; - var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; return { From 2f33c19c646a39b092b3b68039acd53b35dab1ac Mon Sep 17 00:00:00 2001 From: nyteksf Date: Mon, 5 Feb 2018 15:11:46 -0800 Subject: [PATCH 4/7] Whitespace --- tinycolor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 58de217..01eda39 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -303,6 +303,7 @@ tinycolor.fromRatio = function(color, opts) { // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" // function inputToRGB(color) { + var rgb = { r: 0, g: 0, b: 0 }; var a = 1; var s = null; @@ -362,9 +363,8 @@ function inputToRGB(color) { } a = color.a; } - if (tooManyCommas) ok = false; /* If false, format invalid */ + if (tooManyCommas) ok = false; /* If false, format used is invalid */ } - a = boundAlpha(a); return { @@ -1074,7 +1074,7 @@ function convertHexToDecimal(h) { var matchers = (function() { - + // var CSS_INTEGER = "[-\\+]?\\d+%?"; From dadb10995fe3e5eb68729313cfbe504bfaf0fcd6 Mon Sep 17 00:00:00 2001 From: nyteksf Date: Mon, 5 Feb 2018 15:39:35 -0800 Subject: [PATCH 5/7] Fixed mixed tabs and spaces, removed es6 --- tinycolor.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 01eda39..e70cf31 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -313,12 +313,11 @@ function inputToRGB(color) { var tooManyCommas = false; var format = false; - /* Add check for proper comma usage */ var colorSplitToArray = "" + color.split(","); - for(let i=0, len=colorSplitToArray.length; i 360 || color.s < 0 || color.s > 100 || color.l < 0 || color.l > 100) { - ok = false; /* value out of bounds */ + ok = false; } else { - ok = true; /* valid range used */ + ok = true; } s = convertToPercentage(color.s); l = convertToPercentage(color.l); @@ -356,14 +353,13 @@ function inputToRGB(color) { format = "hsl"; } - /* Add validation of color.a values */ if (color.hasOwnProperty("a")) { if (format === "hsl" && color.a > 1 || color.a < 0) { ok = false; } a = color.a; } - if (tooManyCommas) ok = false; /* If false, format used is invalid */ + if (tooManyCommas) ok = false; } a = boundAlpha(a); From cb4c65ebf927c920180b1a025ae4ad71ca4a6c03 Mon Sep 17 00:00:00 2001 From: nyteksf Date: Mon, 5 Feb 2018 15:42:40 -0800 Subject: [PATCH 6/7] Mixed tabs, spaces fix --- tinycolor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinycolor.js b/tinycolor.js index e70cf31..95b0c0a 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -316,7 +316,7 @@ function inputToRGB(color) { var colorSplitToArray = "" + color.split(","); for(var i=0, len=colorSplitToArray.length; i Date: Mon, 5 Feb 2018 15:46:13 -0800 Subject: [PATCH 7/7] re: prior --- tinycolor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 95b0c0a..0cb2a56 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -315,8 +315,8 @@ function inputToRGB(color) { var colorSplitToArray = "" + color.split(","); for(var i=0, len=colorSplitToArray.length; i