From 96f48226cb2b6d53a05c2c820cb62ebbaac5e8da Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Thu, 14 Sep 2017 13:19:13 -0700 Subject: [PATCH] [fix] ColorPropType validation Check color is of type string before using `indexOf`. Fix #630 --- src/propTypes/ColorPropType.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/propTypes/ColorPropType.js b/src/propTypes/ColorPropType.js index 07df65b6..628cc69d 100644 --- a/src/propTypes/ColorPropType.js +++ b/src/propTypes/ColorPropType.js @@ -10,6 +10,9 @@ * @flow */ +const isWebColor = (color: string) => + color === 'currentcolor' || color === 'inherit' || color.indexOf('var(') === 0; + const colorPropType = function(isRequired, props, propName, componentName, location, propFullName) { const normalizeColor = require('normalize-css-color'); const color = props[propName]; @@ -35,8 +38,8 @@ const colorPropType = function(isRequired, props, propName, componentName, locat return; } - // Web supports additional color keywords and custom property values - if (color === 'currentcolor' || color === 'inherit' || color.indexOf('var(') === 0) { + if (typeof color === 'string' && isWebColor(color)) { + // Web supports additional color keywords and custom property values. Ignore them. return; }