Skip to content

Commit

Permalink
Fix picking a null property with a dotted value.
Browse files Browse the repository at this point in the history
  • Loading branch information
fauria committed Mar 5, 2015
1 parent 2a78bf4 commit a45c4a7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ DotObject.prototype.pick = function(path, obj, remove) {
if (path.indexOf(this.seperator) !== -1) {
keys = path.split(this.seperator);
for (i = 0; i < keys.length; i++) {
if (obj.hasOwnProperty(keys[i])) {
if (obj && obj.hasOwnProperty(keys[i])) {
if (i === (keys.length - 1)) {
if (remove) {
val = obj[keys[i]];
Expand Down
42 changes: 42 additions & 0 deletions test/pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,46 @@ describe('DJ value picker:', function() {

});

it('Should be able to pick null properties', function() {

var dj = new DJ();

var obj = {
'some': null
};

var val = dj.pick('some', obj);

(val === null).should.be.true;

});

it('Should return undefined when picking an non-existing value', function() {

var dj = new DJ();

var obj = {
'some': null
};

var val = dj.pick('other', obj);

(val === undefined).should.be.true;

});

it('Should return undefined when picking an non-existing dotted value', function() {

var dj = new DJ();

var obj = {
'some': null
};

var val = dj.pick('some.other', obj);

(val === undefined).should.be.true;

});

});

0 comments on commit a45c4a7

Please sign in to comment.