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.
This commit is contained in:
parent
467ab753c8
commit
b6699aba2d
2 changed files with 4 additions and 1 deletions
|
@ -44,7 +44,7 @@ Memory.prototype.get = function (key) {
|
||||||
//
|
//
|
||||||
while (path.length > 0) {
|
while (path.length > 0) {
|
||||||
key = path.shift();
|
key = path.shift();
|
||||||
if (target && target.hasOwnProperty(key)) {
|
if (target && typeof target !== 'string' && target.hasOwnProperty(key)) {
|
||||||
target = target[key];
|
target = target[key];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,9 @@ vows.describe('nconf').addBatch({
|
||||||
"without a callback": {
|
"without a callback": {
|
||||||
"should respond with the correct value": function () {
|
"should respond with the correct value": function () {
|
||||||
assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
|
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": {
|
"with a callback": {
|
||||||
|
|
Loading…
Reference in a new issue