Skip to content

Commit

Permalink
Add support for objects with a null prototype in objectOf
Browse files Browse the repository at this point in the history
  • Loading branch information
getkey committed Jun 19, 2018
1 parent a9ebdeb commit fb7d4d3
Show file tree
Hide file tree
Showing 2 changed files with 7 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
2 changes: 1 addition & 1 deletion factoryWithTypeCheckers.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,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 (Object.prototype.hasOwnProperty.call(propValue, key)) {
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
if (error instanceof Error) {
return error;
Expand Down

0 comments on commit fb7d4d3

Please sign in to comment.