Skip to content

Commit

Permalink
Fix default value issue when last part of part of path is undefined (#75
Browse files Browse the repository at this point in the history
)
  • Loading branch information
johansteffner authored Nov 19, 2020
1 parent 0f8abf4 commit dcc7f73
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = {
}
}

return object;
return object === undefined ? value : object;
},

set(object, path, value) {
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test('get', t => {
t.is(dotProp.get({foo: {bar: 'a'}}, 'foo.fake'), undefined);
t.is(dotProp.get({foo: {bar: 'a'}}, 'foo.fake.fake2'), undefined);
t.is(dotProp.get({foo: {bar: 'a'}}, 'foo.fake.fake2', 'some value'), 'some value');
t.is(dotProp.get({foo: {}}, 'foo.fake', 'some value'), 'some value');
t.is(dotProp.get({'\\': true}, '\\'), true);
t.is(dotProp.get({'\\foo': true}, '\\foo'), true);
t.is(dotProp.get({'bar\\': true}, 'bar\\'), true);
Expand Down

0 comments on commit dcc7f73

Please sign in to comment.