[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

View File

@@ -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;
}