From f19f0b6c3927aaa5b228bdcb55baf6539f1dac63 Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 20 Dec 2012 14:01:04 -0500 Subject: [PATCH 1/3] [test] Added failing test to illustrate #65 --- test/stores/memory-store-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/stores/memory-store-test.js b/test/stores/memory-store-test.js index a64c8d3..61b07ec 100644 --- a/test/stores/memory-store-test.js +++ b/test/stores/memory-store-test.js @@ -25,6 +25,7 @@ vows.describe('nconf/stores/memory').addBatch({ "the get() method": { "should respond with the correct value": function (store) { assert.equal(store.get('foo:bar:bazz'), 'buzz'); + assert.isUndefined(store.get('foo:bar:bazz:buzz:bizz')); assert.equal(store.get('falsy:number'), 0); assert.equal(store.get('falsy:string'), ''); assert.equal(store.get('falsy:boolean'), false); From 0d795ecf81613bd66229410395b2b4affc9a034d Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 20 Dec 2012 14:08:36 -0500 Subject: [PATCH 2/3] [test] Better tests to show #65 --- test/stores/memory-store-test.js | 47 ++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/test/stores/memory-store-test.js b/test/stores/memory-store-test.js index 61b07ec..f79fd50 100644 --- a/test/stores/memory-store-test.js +++ b/test/stores/memory-store-test.js @@ -17,7 +17,8 @@ vows.describe('nconf/stores/memory').addBatch({ "should respond with true": function (store) { assert.isTrue(store.set('foo:bar:bazz', 'buzz')); assert.isTrue(store.set('falsy:number', 0)); - assert.isTrue(store.set('falsy:string', '')); + assert.isTrue(store.set('falsy:string:empty', '')); + assert.isTrue(store.set('falsy:string:value', 'value')); assert.isTrue(store.set('falsy:boolean', false)); assert.isTrue(store.set('falsy:object', null)); } @@ -25,21 +26,43 @@ vows.describe('nconf/stores/memory').addBatch({ "the get() method": { "should respond with the correct value": function (store) { assert.equal(store.get('foo:bar:bazz'), 'buzz'); - assert.isUndefined(store.get('foo:bar:bazz:buzz:bizz')); assert.equal(store.get('falsy:number'), 0); - assert.equal(store.get('falsy:string'), ''); + assert.equal(store.get('falsy:string:empty'), ''); + assert.equal(store.get('falsy:string:value'), 'value'); assert.equal(store.get('falsy:boolean'), false); assert.equal(store.get('falsy:object'), null); }, - "should not fail when retrieving non-existent keys": function (store) { - assert.doesNotThrow(function() { - assert.equal(store.get('this:key:does:not:exist'), undefined); - }, TypeError); - }, - "should not fail when drilling into non-objects": function (store) { - assert.doesNotThrow(function() { - assert.equal(store.get('falsy:number:uh:oh'), undefined); - }, TypeError); + "should not fail when retrieving non-existent keys": { + "at the root level": function (store) { + assert.doesNotThrow(function() { + assert.equal(store.get('this:key:does:not:exist'), undefined); + }, TypeError); + }, + "within numbers": function (store) { + assert.doesNotThrow(function() { + assert.equal(store.get('falsy:number:not:exist'), undefined); + }, TypeError); + }, + "within booleans": function (store) { + assert.doesNotThrow(function() { + assert.equal(store.get('falsy:boolean:not:exist'), undefined); + }, TypeError); + }, + "within objects": function (store) { + assert.doesNotThrow(function() { + assert.equal(store.get('falsy:object:not:exist'), undefined); + }, TypeError); + }, + "within empty strings": function (store) { + assert.doesNotThrow(function() { + assert.equal(store.get('falsy:string:empty:not:exist'), undefined); + }, TypeError); + }, + "within empty strings": function (store) { + assert.doesNotThrow(function() { + assert.equal(store.get('falsy:string:value:not:exist'), undefined); + }, TypeError); + } } }, "the clear() method": { From 60456186d75fecbd9b6519d932a737bd904ae6f0 Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 20 Dec 2012 18:03:37 -0500 Subject: [PATCH 3/3] [fix] Fix for #65 --- lib/nconf/stores/memory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nconf/stores/memory.js b/lib/nconf/stores/memory.js index b53ac12..a74cc8f 100644 --- a/lib/nconf/stores/memory.js +++ b/lib/nconf/stores/memory.js @@ -42,7 +42,7 @@ Memory.prototype.get = function (key) { // while (path.length > 0) { key = path.shift(); - if (target && key in target) { + if (target && typeof target !== 'string' && key in target) { target = target[key]; continue; }