diff --git a/src/lib/common.js b/src/lib/common.js index 963c2c22..f459dfe4 100644 --- a/src/lib/common.js +++ b/src/lib/common.js @@ -101,10 +101,29 @@ const getConfigEnv = async options => options ) +const sanitizeConfig = config => { + // recurse configuration objects and arrays to remove whitespace + const sanitize = (chunk) => { + return _.reduce(chunk, (result, v, k) => { + if (_.isObject(v) || _.isArray(v)) { + result[k] = sanitize(v); + } else if (_.isString()) { + result[k] = _.trim(v); + } else { + result[k] = v; + } + + return result; + }, _.isArray(chunk) ? [] : {}) + } + + return sanitize(config); +} + const writeConfig = async newConfig => wrapPromise( new Promise(async (resolve, reject) => { - fs.writeFileSync(CONFIG_FILE, JSON.stringify(newConfig, null, 2)) + fs.writeFileSync(CONFIG_FILE, JSON.stringify(sanitizeConfig(newConfig), null, 2)) resolve(getConfigEnv()) }), 'Writing config'