Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #112 from getkey/objectof-null-prototype
Browse files Browse the repository at this point in the history
Add support for objects created with a null prototype in objectOf
  • Loading branch information
gaearon authored Jun 19, 2018
2 parents a9ebdeb + 2200d8d commit cfc7f43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions __tests__/PropTypesDevelopmentStandalone-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion factoryWithTypeCheckers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit cfc7f43

Please sign in to comment.