mirror of
https://github.com/less/less.js.git
synced 2026-01-23 06:07:56 -05:00
Added more flexible check for HEX color code. Also error is now less specific.
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user