Skip to content

Commit c872caa

Browse files
committed
Merge pull request #1976 from peruginni/master
Added condition to check if HEX code contain only valid characters (issue #1015)
2 parents cd63bc5 + a5406a9 commit c872caa

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

lib/less/parser.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +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+
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+
}
963968
return new(tree.Color)(rgb[1]);
964969
}
965970
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.a {
2+
@wrongHEXColorCode: #DCALLB;
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SyntaxError: Invalid HEX color code in {path}color-invalid-hex-code.less on line 2, column 29:
2+
1 .a {
3+
2 @wrongHEXColorCode: #DCALLB;
4+
3 }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.a {
2+
@wrongHEXColorCode: #fffblack;
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SyntaxError: Invalid HEX color code in {path}color-invalid-hex-code2.less on line 2, column 29:
2+
1 .a {
3+
2 @wrongHEXColorCode: #fffblack;
4+
3 }

0 commit comments

Comments
 (0)