From 0444c42b5cf2d7f5fe44bc42e0f71dc99debcedc Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sun, 10 Dec 2017 03:28:16 -0600 Subject: [PATCH] fix: config handler should check if value is null (#1134) --- src/http/api/resources/config.js | 5 +++-- test/cli/config.js | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/http/api/resources/config.js b/src/http/api/resources/config.js index fec1fea76e..eb0c1af9a3 100644 --- a/src/http/api/resources/config.js +++ b/src/http/api/resources/config.js @@ -59,8 +59,9 @@ exports.getOrSet = { const value = request.pre.args.value const ipfs = request.server.app.ipfs - if (typeof value === 'object' && - value.type === 'Buffer') { + // check that value exists - typeof null === 'object' + if (value && (typeof value === 'object' && + value.type === 'Buffer')) { return reply({ Message: 'Invalid value type', Code: 0 diff --git a/test/cli/config.js b/test/cli/config.js index 5f3e72c460..76d3c77f3d 100644 --- a/test/cli/config.js +++ b/test/cli/config.js @@ -45,6 +45,12 @@ describe('config', () => runOnAndOff((thing) => { }) }) + it('set a config key with null', () => { + return ipfs('config foo null --json').then((out) => { + expect(updatedConfig().foo).to.equal(null) + }) + }) + it('set a config key with json', () => { return ipfs('config foo {"bar":0} --json').then((out) => { expect(updatedConfig().foo).to.deep.equal({ bar: 0 })