Skip to content

Commit

Permalink
Return default value if path is invalid (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
Richienb and sindresorhus committed Sep 8, 2021
1 parent 09adad9 commit d400c8d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -39,7 +39,7 @@ module.exports = {

const pathArray = getPathSegments(path);
if (pathArray.length === 0) {
return;
return value;
}

for (let i = 0; i < pathArray.length; i++) {
Expand Down
4 changes: 4 additions & 0 deletions test.js
Expand Up @@ -213,3 +213,7 @@ test('prevent setting/getting `__proto__`', t => {

t.is(dotProp.get({}, '__proto__'), undefined);
});

test('return default value if path is invalid', t => {
t.is(dotProp.get({}, 'constructor', '🦄'), '🦄');
});

0 comments on commit d400c8d

Please sign in to comment.