Skip to content

Commit

Permalink
Write failing test and fix accessing a property of an object with nul…
Browse files Browse the repository at this point in the history
…l prototype.
  • Loading branch information
elektronik2k5 committed Jun 30, 2016
1 parent 60e05c9 commit 1d75e39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
};

function getShallowProperty(obj, prop) {
if(options.includeInheritedProps || (typeof prop === 'number' && Array.isArray(obj)) || obj.hasOwnProperty(prop)) {
if (options.includeInheritedProps || (typeof prop === 'number' && Array.isArray(obj)) || _hasOwnProperty.call(obj, prop)) {
return obj[prop];
}
}
Expand Down
13 changes: 12 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ describe('get', function() {
expect(objectPath.get(undefined, 'test', 'a')).to.be.deep.equal('a');
});

it(
'should not fail on an object with a null prototype',
function assertSuccessForObjWithNullProto(){
// TODO: verify this works on node 0.10
var foo = 'FOO';
var objWithNullProto = Object.create(null);
objWithNullProto.foo = foo;
expect(objectPath.get(objWithNullProto, 'foo')).to.equal(foo);
}
);

it('should skip non own properties', function() {
var Base = function(enabled){ };
Base.prototype = {
Expand Down Expand Up @@ -772,7 +783,7 @@ describe('bind object', function () {
});
});

describe('Don\' access not own properties [default]', function () {
describe('Don\'t access not own properties [default]', function () {
it('should not get a not own property', function() {
var Obj = function() {};
Obj.prototype.notOwn = {a: 'a'};
Expand Down

0 comments on commit 1d75e39

Please sign in to comment.