diff --git a/__tests__/PropTypesDevelopmentStandalone-test.js b/__tests__/PropTypesDevelopmentStandalone-test.js index cea794e..4267b6e 100644 --- a/__tests__/PropTypesDevelopmentStandalone-test.js +++ b/__tests__/PropTypesDevelopmentStandalone-test.js @@ -723,6 +723,12 @@ describe('PropTypesDevelopmentStandalone', () => { }); }); + it('should support objects with a null prototype', () => { + const nullObj = Object.create(null); + nullObj.test = "a property"; + typeCheckPass(PropTypes.objectOf(PropTypes.string), nullObj); + }); + it('should warn with invalid items in the object', () => { typeCheckFail( PropTypes.objectOf(PropTypes.number), diff --git a/factoryWithTypeCheckers.js b/factoryWithTypeCheckers.js index c41e3bb..1942d0e 100644 --- a/factoryWithTypeCheckers.js +++ b/factoryWithTypeCheckers.js @@ -12,6 +12,7 @@ var assign = require('object-assign'); var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret'); var checkPropTypes = require('./checkPropTypes'); +var has = Function.call.bind(Object.prototype.hasOwnProperty); var printWarning = function() {}; if (process.env.NODE_ENV !== 'production') { @@ -318,7 +319,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) { return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); } for (var key in propValue) { - if (propValue.hasOwnProperty(key)) { + if (has(propValue, key)) { var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); if (error instanceof Error) { return error;