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

Add support for objects created with a null prototype in objectOf #112

Merged
merged 4 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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