Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit a3d98a8

Browse files
committed
fix(config): support null values (0 or empty string) on get and set
1 parent 56904fd commit a3d98a8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@
8080
"joi": "^9.0.4",
8181
"libp2p-ipfs": "^0.12.1",
8282
"libp2p-ipfs-browser": "^0.12.1",
83+
"lodash.get": "^4.4.1",
84+
"lodash.has": "^4.5.2",
85+
"lodash.set": "^4.3.1",
8386
"lodash.sortby": "^4.6.1",
8487
"mafmt": "^2.1.1",
8588
"map-limit": "0.0.1",
86-
"lodash.get": "^4.4.1",
87-
"lodash.set": "^4.3.1",
8889
"multiaddr": "^2.0.2",
8990
"multihashes": "^0.2.2",
9091
"path-exists": "^3.0.0",

src/core/ipfs/config.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const promisify = require('promisify-es6')
44
const _get = require('lodash.get')
5+
const _has = require('lodash.has')
56
const _set = require('lodash.set')
67

78
module.exports = function config (self) {
@@ -24,11 +25,11 @@ module.exports = function config (self) {
2425
if (err) {
2526
return callback(err)
2627
}
27-
const value = _get(config, key, undefined)
28-
if (!value) {
29-
callback(new Error('Key does not exist in config'))
30-
} else {
28+
if (_has(config, key)) {
29+
const value = _get(config, key, undefined)
3130
callback(null, value)
31+
} else {
32+
callback(new Error('Key does not exist in config'))
3233
}
3334
})
3435
}),
@@ -37,7 +38,7 @@ module.exports = function config (self) {
3738
return callback(new Error('Invalid key type'))
3839
}
3940

40-
if (!value || Buffer.isBuffer(value)) {
41+
if (value === undefined || Buffer.isBuffer(value)) {
4142
return callback(new Error('Invalid value type'))
4243
}
4344

0 commit comments

Comments
 (0)