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.
master
bryce-gibson 2017-11-05 12:39:00 +11:00 committed by Matt Hamann
parent 467ab753c8
commit b6699aba2d
2 changed files with 4 additions and 1 deletions

View File

@ -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;
}

View File

@ -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": {