From a3d98a8464d07fbec46f69ca0c045ec14e174c2f Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 23 Aug 2016 14:48:43 +0100 Subject: [PATCH] fix(config): support null values (0 or empty string) on get and set --- package.json | 5 +++-- src/core/ipfs/config.js | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index cfcf8e5961..2d79f6fb11 100644 --- a/package.json +++ b/package.json @@ -80,11 +80,12 @@ "joi": "^9.0.4", "libp2p-ipfs": "^0.12.1", "libp2p-ipfs-browser": "^0.12.1", + "lodash.get": "^4.4.1", + "lodash.has": "^4.5.2", + "lodash.set": "^4.3.1", "lodash.sortby": "^4.6.1", "mafmt": "^2.1.1", "map-limit": "0.0.1", - "lodash.get": "^4.4.1", - "lodash.set": "^4.3.1", "multiaddr": "^2.0.2", "multihashes": "^0.2.2", "path-exists": "^3.0.0", diff --git a/src/core/ipfs/config.js b/src/core/ipfs/config.js index 72942bb22e..4fa5ec1189 100644 --- a/src/core/ipfs/config.js +++ b/src/core/ipfs/config.js @@ -2,6 +2,7 @@ const promisify = require('promisify-es6') const _get = require('lodash.get') +const _has = require('lodash.has') const _set = require('lodash.set') module.exports = function config (self) { @@ -24,11 +25,11 @@ module.exports = function config (self) { if (err) { return callback(err) } - const value = _get(config, key, undefined) - if (!value) { - callback(new Error('Key does not exist in config')) - } else { + if (_has(config, key)) { + const value = _get(config, key, undefined) callback(null, value) + } else { + callback(new Error('Key does not exist in config')) } }) }), @@ -37,7 +38,7 @@ module.exports = function config (self) { return callback(new Error('Invalid key type')) } - if (!value || Buffer.isBuffer(value)) { + if (value === undefined || Buffer.isBuffer(value)) { return callback(new Error('Invalid value type')) }