Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions __tests__/PropTypesDevelopmentStandalone-test.js
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
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