Skip to content

Commit

Permalink
Fix issue where color-string with incorrectly return a color for prop…
Browse files Browse the repository at this point in the history
…erties on Object's prototype like "constructor".

Closes #44.

Reviewed by @tolmasky.
  • Loading branch information
tolmasky authored and Qix- committed Nov 26, 2021
1 parent b7c685f commit 20e55f3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
@@ -1,12 +1,13 @@
/* MIT license */
var colorNames = require('color-name');
var swizzle = require('simple-swizzle');
var hasOwnProperty = Object.hasOwnProperty;

var reverseNames = {};

// create a list of reverse color names
for (var name in colorNames) {
if (colorNames.hasOwnProperty(name)) {
if (hasOwnProperty.call(colorNames, name)) {
reverseNames[colorNames[name]] = name;
}
}
Expand Down Expand Up @@ -111,12 +112,11 @@ cs.get.rgb = function (string) {
return [0, 0, 0, 0];
}

rgb = colorNames[match[1]];

if (!rgb) {
if (!hasOwnProperty.call(colorNames, match[1])) {
return null;
}

rgb = colorNames[match[1]];
rgb[3] = 1;

return rgb;
Expand Down

0 comments on commit 20e55f3

Please sign in to comment.