Skip to content

Commit

Permalink
Merge pull request #1976 from peruginni/master
Browse files Browse the repository at this point in the history
Added condition to check if HEX code contain only valid characters (issue #1015)
  • Loading branch information
lukeapage committed Jun 6, 2014
2 parents cd63bc5 + a5406a9 commit c872caa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/less/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +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})/))) {
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]);
}
},
Expand Down
3 changes: 3 additions & 0 deletions test/less/errors/color-invalid-hex-code.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.a {
@wrongHEXColorCode: #DCALLB;
}
4 changes: 4 additions & 0 deletions test/less/errors/color-invalid-hex-code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SyntaxError: Invalid HEX color code in {path}color-invalid-hex-code.less on line 2, column 29:
1 .a {
2 @wrongHEXColorCode: #DCALLB;
3 }
3 changes: 3 additions & 0 deletions test/less/errors/color-invalid-hex-code2.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.a {
@wrongHEXColorCode: #fffblack;
}
4 changes: 4 additions & 0 deletions test/less/errors/color-invalid-hex-code2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SyntaxError: Invalid HEX color code in {path}color-invalid-hex-code2.less on line 2, column 29:
1 .a {
2 @wrongHEXColorCode: #fffblack;
3 }

0 comments on commit c872caa

Please sign in to comment.