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

Commit cfc7f43

Browse files
authored
Merge pull request #112 from getkey/objectof-null-prototype
Add support for objects created with a null prototype in objectOf
2 parents a9ebdeb + 2200d8d commit cfc7f43

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

__tests__/PropTypesDevelopmentStandalone-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@ describe('PropTypesDevelopmentStandalone', () => {
723723
});
724724
});
725725

726+
it('should support objects with a null prototype', () => {
727+
const nullObj = Object.create(null);
728+
nullObj.test = "a property";
729+
typeCheckPass(PropTypes.objectOf(PropTypes.string), nullObj);
730+
});
731+
726732
it('should warn with invalid items in the object', () => {
727733
typeCheckFail(
728734
PropTypes.objectOf(PropTypes.number),

factoryWithTypeCheckers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var assign = require('object-assign');
1212
var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
1313
var checkPropTypes = require('./checkPropTypes');
1414

15+
var has = Function.call.bind(Object.prototype.hasOwnProperty);
1516
var printWarning = function() {};
1617

1718
if (process.env.NODE_ENV !== 'production') {
@@ -318,7 +319,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
318319
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
319320
}
320321
for (var key in propValue) {
321-
if (propValue.hasOwnProperty(key)) {
322+
if (has(propValue, key)) {
322323
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
323324
if (error instanceof Error) {
324325
return error;

0 commit comments

Comments
 (0)