diff --git a/lib/less/parser.js b/lib/less/parser.js index b1e24e92..7159fa24 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 77e29f05..0f8a82ce 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 }