Skip to content

Commit e75f78b

Browse files
Merge pull request #71 from elektronik2k5/bugfix/dont-fail-on-object-with-null-proto
Bugfix: don't fail on object with null proto
2 parents 60e05c9 + c72579f commit e75f78b

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
};
8080

8181
function getShallowProperty(obj, prop) {
82-
if(options.includeInheritedProps || (typeof prop === 'number' && Array.isArray(obj)) || obj.hasOwnProperty(prop)) {
82+
if (options.includeInheritedProps || (typeof prop === 'number' && Array.isArray(obj)) || _hasOwnProperty.call(obj, prop)) {
8383
return obj[prop];
8484
}
8585
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "object-path",
33
"description": "Access deep object properties using a path",
4-
"version": "0.11.0",
4+
"version": "0.11.1",
55
"author": {
66
"name": "Mario Casciaro"
77
},

test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ describe('get', function() {
102102
expect(objectPath.get(undefined, 'test', 'a')).to.be.deep.equal('a');
103103
});
104104

105+
it(
106+
'should not fail on an object with a null prototype',
107+
function assertSuccessForObjWithNullProto(){
108+
var foo = 'FOO';
109+
var objWithNullProto = Object.create(null);
110+
objWithNullProto.foo = foo;
111+
expect(objectPath.get(objWithNullProto, 'foo')).to.equal(foo);
112+
}
113+
);
114+
105115
it('should skip non own properties', function() {
106116
var Base = function(enabled){ };
107117
Base.prototype = {
@@ -772,7 +782,7 @@ describe('bind object', function () {
772782
});
773783
});
774784

775-
describe('Don\' access not own properties [default]', function () {
785+
describe('Don\'t access not own properties [default]', function () {
776786
it('should not get a not own property', function() {
777787
var Obj = function() {};
778788
Obj.prototype.notOwn = {a: 'a'};

0 commit comments

Comments
 (0)