Skip to content

Commit

Permalink
fix: when first prop is a string lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Feb 8, 2017
1 parent f6a7369 commit 9c7867e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/undefsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ function undefsafe(obj, path, value) {
i++;
c = path.substr(i, 1);
}
res.push(key);

if (key) { // the first value could be a string
res.push(key);
}
key = '';
continue;
}
Expand Down
7 changes: 7 additions & 0 deletions test/undefsafe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ test('should find properties with periods in them', function (t) {
r = undefsafe(value, `a['one.two.and\three'].1`);
t.equal(r, true, 'combo: ' + r);

value = {
'one.two': true
};

r = undefsafe(value, `['one.two']`);
t.equal(r, true, 'root: ' + r);

t.end();
});

Expand Down

0 comments on commit 9c7867e

Please sign in to comment.