Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/lib/isIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function isIn(str, options) {
}
return array.indexOf(str) >= 0;
} else if (typeof options === 'object') {
return options.hasOwnProperty(str);
return Object.prototype.hasOwnProperty.call(options, str);
} else if (options && typeof options.indexOf === 'function') {
return options.indexOf(str) >= 0;
}
Expand Down
33 changes: 33 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6184,6 +6184,39 @@ describe('Validators', () => {
});
});

it('should validate membership in objects with no prototype', () => {
const values = Object.create(null);
values.foo = 1;
values.bar = 2;
test({
validator: 'isIn',
args: [values],
valid: ['foo', 'bar'],
invalid: ['missing', 'toString', 'constructor', ''],
});
});

it('should validate membership when hasOwnProperty is an object key', () => {
test({
validator: 'isIn',
args: [{ foo: 1, hasOwnProperty: 2 }],
valid: ['foo', 'hasOwnProperty'],
invalid: ['missing', 'toString', 'constructor', ''],
});
});

it('should not call an object membership value as hasOwnProperty', () => {
const values = Object.create({ inherited: 1 });
values.foo = 1;
values.hasOwnProperty = () => true;
test({
validator: 'isIn',
args: [values],
valid: ['foo', 'hasOwnProperty'],
invalid: ['missing', 'inherited', 'toString', ''],
});
});

it('should validate ABA routing number', () => {
test({
validator: 'isAbaRouting',
Expand Down