Added more flexible check for HEX color code. Also error is now less specific.

This commit is contained in:
Ondřej Macoszek
2014-05-08 12:12:06 +02:00
parent 31ffdb8c9f
commit 5b8b8def23
2 changed files with 6 additions and 7 deletions

View File

@@ -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]);
}
},

View File

@@ -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 }