From 4322018157ab5f8ca5ffe03ff8d415c570bbcd81 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Fri, 5 Feb 2016 11:27:10 +0100 Subject: [PATCH] Handle null subobject case --- lib/config.js | 3 ++- test/2-config-test.js | 4 ++++ test/config/default.yaml | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index e9e69a3b..341a9630 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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)); diff --git a/test/2-config-test.js b/test/2-config-test.js index f3a6435e..34965c99 100644 --- a/test/2-config-test.js +++ b/test/2-config-test.js @@ -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')); }, diff --git a/test/config/default.yaml b/test/config/default.yaml index daf85996..d60b8d7d 100644 --- a/test/config/default.yaml +++ b/test/config/default.yaml @@ -3,6 +3,8 @@ Customers: dbPort: 5984 dbName: from_default_yaml + emptySub: + # empty AnotherModule: parm2: value2