From 2e26e07f921575dbb10c049eaa7a864867e696c6 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Fri, 9 Oct 2020 12:19:01 +0200 Subject: [PATCH] fix: Ensure to preserve `undefined` valued propeties as `undefined` --- lib/classes/ConfigSchemaHandler/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/classes/ConfigSchemaHandler/index.js b/lib/classes/ConfigSchemaHandler/index.js index 205ffaceca1..5046bd1b817 100644 --- a/lib/classes/ConfigSchemaHandler/index.js +++ b/lib/classes/ConfigSchemaHandler/index.js @@ -27,7 +27,7 @@ const normalizeSchemaObject = (object, instanceSchema) => { // normalizedObjectsMap allows to handle circular structures without issues const normalizeUserConfig = userConfig => { const normalizedObjectsSet = new WeakSet(); - const nullPaths = []; + const removedValuesMap = []; const normalizeObject = (object, path) => { if (normalizedObjectsSet.has(object)) return; normalizedObjectsSet.add(object); @@ -38,7 +38,7 @@ const normalizeUserConfig = userConfig => { } else { for (const [key, value] of Object.entries(object)) { if (value == null) { - nullPaths.push(path.concat(key)); + removedValuesMap.push({ path: path.concat(key), value }); delete object[key]; } else if (_.isObject(value)) { normalizeObject(value, path.concat(key)); @@ -47,10 +47,12 @@ const normalizeUserConfig = userConfig => { } }; normalizeObject(userConfig, []); - return { nullPaths }; + return { removedValuesMap }; }; -const denormalizeUserConfig = (userConfig, { nullPaths }) => { - for (const nullPath of nullPaths) _.set(userConfig, nullPath, null); +const denormalizeUserConfig = (userConfig, { removedValuesMap }) => { + for (const removedValueData of removedValuesMap) { + _.set(userConfig, removedValueData.path, removedValueData.value); + } }; class ConfigSchemaHandler {