From b6699aba2dac63dfc193f2bd31dc60cfa2ecc060 Mon Sep 17 00:00:00 2001 From: bryce-gibson Date: Sun, 5 Nov 2017 12:39:00 +1100 Subject: [PATCH] Don't do array lookups on strings. (#188) `hasOwnProperty(number)` can return true for strings. This is unlikely to be the desired usage, and can mean that odd responses are returned by nconf. Disable trying to check `hasOwnProperty` of strings. --- lib/nconf/stores/memory.js | 2 +- test/nconf-test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/nconf/stores/memory.js b/lib/nconf/stores/memory.js index db71387..52c3429 100644 --- a/lib/nconf/stores/memory.js +++ b/lib/nconf/stores/memory.js @@ -44,7 +44,7 @@ Memory.prototype.get = function (key) { // while (path.length > 0) { key = path.shift(); - if (target && target.hasOwnProperty(key)) { + if (target && typeof target !== 'string' && target.hasOwnProperty(key)) { target = target[key]; continue; } diff --git a/test/nconf-test.js b/test/nconf-test.js index dddbabf..76394b8 100644 --- a/test/nconf-test.js +++ b/test/nconf-test.js @@ -67,6 +67,9 @@ vows.describe('nconf').addBatch({ "without a callback": { "should respond with the correct value": function () { assert.equal(nconf.get('foo:bar:bazz'), 'buzz'); + }, + "should not step inside strings": function () { + assert.equal(nconf.get('foo:bar:bazz:0'), undefined); } }, "with a callback": {