Merge pull request #63 from SchoonologyRRL/patch-1
Updated Memory.merge to handle null values
This commit is contained in:
commit
818526ca62
4 changed files with 12 additions and 3 deletions
|
@ -157,7 +157,7 @@ Memory.prototype.merge = function (key, value) {
|
||||||
// If the key is not an `Object` or is an `Array`,
|
// If the key is not an `Object` or is an `Array`,
|
||||||
// then simply set it. Merging is for Objects.
|
// then simply set it. Merging is for Objects.
|
||||||
//
|
//
|
||||||
if (typeof value !== 'object' || Array.isArray(value)) {
|
if (typeof value !== 'object' || Array.isArray(value) || value === null) {
|
||||||
return this.set(key, value);
|
return this.set(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
test/fixtures/merge/file1.json
vendored
3
test/fixtures/merge/file1.json
vendored
|
@ -12,5 +12,8 @@
|
||||||
"first": 1,
|
"first": 1,
|
||||||
"second": 2
|
"second": 2
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"unicorn": {
|
||||||
|
"exists": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
test/fixtures/merge/file2.json
vendored
3
test/fixtures/merge/file2.json
vendored
|
@ -5,5 +5,6 @@
|
||||||
"something4": true
|
"something4": true
|
||||||
},
|
},
|
||||||
"dates": true,
|
"dates": true,
|
||||||
"elderberries": true
|
"elderberries": true,
|
||||||
|
"unicorn": null
|
||||||
}
|
}
|
|
@ -84,6 +84,11 @@ vows.describe('nconf/provider').addBatch({
|
||||||
provider.merge(override);
|
provider.merge(override);
|
||||||
helpers.assertMerged(null, provider.stores.file.store);
|
helpers.assertMerged(null, provider.stores.file.store);
|
||||||
assert.equal(provider.stores.file.store.candy.something, 'file1');
|
assert.equal(provider.stores.file.store.candy.something, 'file1');
|
||||||
|
},
|
||||||
|
"should merge Objects over null": function (provider) {
|
||||||
|
provider.load();
|
||||||
|
provider.merge(override);
|
||||||
|
assert.equal(provider.stores.file.store.unicorn.exists, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue