Skip to content

Commit 9c7867e

Browse files
committed
fix: when first prop is a string lookup
1 parent f6a7369 commit 9c7867e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/undefsafe.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ function undefsafe(obj, path, value) {
1818
i++;
1919
c = path.substr(i, 1);
2020
}
21-
res.push(key);
21+
22+
if (key) { // the first value could be a string
23+
res.push(key);
24+
}
2225
key = '';
2326
continue;
2427
}

test/undefsafe.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ test('should find properties with periods in them', function (t) {
6666
r = undefsafe(value, `a['one.two.and\three'].1`);
6767
t.equal(r, true, 'combo: ' + r);
6868

69+
value = {
70+
'one.two': true
71+
};
72+
73+
r = undefsafe(value, `['one.two']`);
74+
t.equal(r, true, 'root: ' + r);
75+
6976
t.end();
7077
});
7178

0 commit comments

Comments
 (0)