[fix] ColorPropType validation

Check color is of type string before using `indexOf`.

Fix #630
This commit is contained in:
Nicolas Gallagher
2017-09-14 13:19:13 -07:00
parent f1ef0f21af
commit 96f48226cb
+5 -2
View File
@@ -10,6 +10,9 @@
* @flow * @flow
*/ */
const isWebColor = (color: string) =>
color === 'currentcolor' || color === 'inherit' || color.indexOf('var(') === 0;
const colorPropType = function(isRequired, props, propName, componentName, location, propFullName) { const colorPropType = function(isRequired, props, propName, componentName, location, propFullName) {
const normalizeColor = require('normalize-css-color'); const normalizeColor = require('normalize-css-color');
const color = props[propName]; const color = props[propName];
@@ -35,8 +38,8 @@ const colorPropType = function(isRequired, props, propName, componentName, locat
return; return;
} }
// Web supports additional color keywords and custom property values if (typeof color === 'string' && isWebColor(color)) {
if (color === 'currentcolor' || color === 'inherit' || color.indexOf('var(') === 0) { // Web supports additional color keywords and custom property values. Ignore them.
return; return;
} }