Skip to content

Commit 20e55f3

Browse files
tolmaskyQix-
authored andcommitted
Fix issue where color-string with incorrectly return a color for properties on Object's prototype like "constructor".
Closes #44. Reviewed by @tolmasky.
1 parent b7c685f commit 20e55f3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* MIT license */
22
var colorNames = require('color-name');
33
var swizzle = require('simple-swizzle');
4+
var hasOwnProperty = Object.hasOwnProperty;
45

56
var reverseNames = {};
67

78
// create a list of reverse color names
89
for (var name in colorNames) {
9-
if (colorNames.hasOwnProperty(name)) {
10+
if (hasOwnProperty.call(colorNames, name)) {
1011
reverseNames[colorNames[name]] = name;
1112
}
1213
}
@@ -111,12 +112,11 @@ cs.get.rgb = function (string) {
111112
return [0, 0, 0, 0];
112113
}
113114

114-
rgb = colorNames[match[1]];
115-
116-
if (!rgb) {
115+
if (!hasOwnProperty.call(colorNames, match[1])) {
117116
return null;
118117
}
119118

119+
rgb = colorNames[match[1]];
120120
rgb[3] = 1;
121121

122122
return rgb;

0 commit comments

Comments
 (0)