Skip to content

Commit 9a1631a

Browse files
committedFeb 21, 2017
fix: handle null as the root object
1 parent 9c7867e commit 9a1631a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
 

‎lib/undefsafe.js

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ function undefsafe(obj, path, value) {
4040
return res;
4141
}
4242

43+
// bail if there's nothing
44+
if (obj === undefined || obj === null) {
45+
return undefined;
46+
}
47+
4348
var parts = split(path);
4449
var key = null;
4550
var type = typeof obj;

‎test/undefsafe.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ test('should handle primatives', function (t) {
88
t.end();
99
});
1010

11+
test('should handle null', function (t) {
12+
var r = undefsafe(null, 'foo');
13+
t.equal(r, undefined, 'undefsafe works with null');
14+
t.end();
15+
});
16+
1117
test('should handle empty objects', function (t) {
1218
var value = {};
1319
var r;

0 commit comments

Comments
 (0)
Please sign in to comment.