Skip to content

Commit 5b8b8de

Browse files
committed
Added more flexible check for HEX color code. Also error is now less specific.
1 parent 31ffdb8 commit 5b8b8de

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/less/parser.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -960,12 +960,11 @@ less.Parser = function Parser(env) {
960960
var rgb;
961961

962962
if (input.charAt(i) === '#' && (rgb = $re(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/))) {
963-
if (rgb[1].length === 3) {
964-
var followingCharacter = rgb.input.substring(4,5);
965-
if (followingCharacter.match(/[A-Za-z]{1}/)) {
966-
error("Some characters in HEX code are not valid. (see issue #1015)");
967-
}
968-
}
963+
var colorCandidateString = rgb.input.match(/^#([\w]+).*/); // strip colons, brackets, whitespaces and other characters that should not definitely be part of color string
964+
colorCandidateString = colorCandidateString[1];
965+
if (!colorCandidateString.match(/^[A-Fa-f0-9]+$/)) { // verify if candidate consists only of allowed HEX characters
966+
error("Invalid HEX color code");
967+
}
969968
return new(tree.Color)(rgb[1]);
970969
}
971970
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SyntaxError: Some characters in HEX code are not valid. (see issue #1015) in {path}color-invalid-hex-code.less on line 2, column 29:
1+
SyntaxError: Invalid HEX color code in {path}color-invalid-hex-code.less on line 2, column 29:
22
1 .a {
33
2 @wrongHEXColorCode: #DCALLB;
44
3 }

0 commit comments

Comments
 (0)