[Pkg-javascript-commits] [less.js] 28/50: Added more flexible check for HEX color code. Also error is now less specific.

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:22:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v1.7.1
in repository less.js.

commit 5b8b8def235da9dfe8d913021f968bdb3b86acbf
Author: Ondřej Macoszek <ondra at macoszek.cz>
Date:   Thu May 8 12:12:06 2014 +0200

    Added more flexible check for HEX color code. Also error is now less specific.
---
 lib/less/parser.js                          | 11 +++++------
 test/less/errors/color-invalid-hex-code.txt |  2 +-
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/less/parser.js b/lib/less/parser.js
index b1e24e9..7159fa2 100644
--- a/lib/less/parser.js
+++ b/lib/less/parser.js
@@ -960,12 +960,11 @@ less.Parser = function Parser(env) {
                     var rgb;
 
                     if (input.charAt(i) === '#' && (rgb = $re(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/))) {
-                        if (rgb[1].length === 3) {
-                            var followingCharacter = rgb.input.substring(4,5);
-                            if (followingCharacter.match(/[A-Za-z]{1}/)) {
-                                error("Some characters in HEX code are not valid. (see issue #1015)");
-                            }
-                        }
+                        var colorCandidateString = rgb.input.match(/^#([\w]+).*/); // strip colons, brackets, whitespaces and other characters that should not definitely be part of color string
+                        colorCandidateString = colorCandidateString[1];
+                        if (!colorCandidateString.match(/^[A-Fa-f0-9]+$/)) { // verify if candidate consists only of allowed HEX characters
+                            error("Invalid HEX color code");
+                        } 
                         return new(tree.Color)(rgb[1]);
                     }
                 },
diff --git a/test/less/errors/color-invalid-hex-code.txt b/test/less/errors/color-invalid-hex-code.txt
index 77e29f0..0f8a82c 100644
--- a/test/less/errors/color-invalid-hex-code.txt
+++ b/test/less/errors/color-invalid-hex-code.txt
@@ -1,4 +1,4 @@
-SyntaxError: Some characters in HEX code are not valid. (see issue #1015) in {path}color-invalid-hex-code.less on line 2, column 29:
+SyntaxError: Invalid HEX color code in {path}color-invalid-hex-code.less on line 2, column 29:
 1 .a {
 2     @wrongHEXColorCode: #DCALLB;
 3 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list