Skip to content

Commit

Permalink
Merge pull request #289 from Yaska/master
Browse files Browse the repository at this point in the history
Handle null subobject case
  • Loading branch information
lorenwest committed Feb 5, 2016
2 parents dc0ca71 + 4322018 commit 934b416
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/config.js
Expand Up @@ -145,7 +145,8 @@ var getImpl= function(object, property) {
if (elems.length <= 1) {
return value;
}
if (typeof value !== 'object') {
// Note that typeof null === 'object'
if (value === null || typeof value !== 'object') {
return undefined;
}
return getImpl(value, elems.slice(1));
Expand Down
4 changes: 4 additions & 0 deletions test/2-config-test.js
Expand Up @@ -276,6 +276,10 @@ vows.describe('Test suite for node-config')
'A sub level item can be tested': function() {
assert.isTrue(CONFIG.has('Customers.dbHost'));
},
'A missing sub level item can be tested': function() {
assert.isTrue(CONFIG.has('Customers.emptySub'));
assert.isFalse(CONFIG.has('Customers.emptySub.foo'));
},
'has is attached deeply': function() {
assert.isTrue(CONFIG.Customers.has('dbHost'));
},
Expand Down
2 changes: 2 additions & 0 deletions test/config/default.yaml
Expand Up @@ -3,6 +3,8 @@
Customers:
dbPort: 5984
dbName: from_default_yaml
emptySub:
# empty

AnotherModule:
parm2: value2
Expand Down

0 comments on commit 934b416

Please sign in to comment.