From a1aa995a7afa1babead4dad180755f79290dfb32 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 4 Aug 2019 16:47:42 +0300 Subject: [PATCH] Fix for non-object-literals in deepKeyIntersect --- src/plugins/ZeppelinPlugin.ts | 5 ++++- src/utils.ts | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/plugins/ZeppelinPlugin.ts b/src/plugins/ZeppelinPlugin.ts index da252d9c..ed71efa4 100644 --- a/src/plugins/ZeppelinPlugin.ts +++ b/src/plugins/ZeppelinPlugin.ts @@ -86,7 +86,10 @@ export class ZeppelinPlugin extends Plug if (decodedOverrideConfig instanceof StrictValidationError) { throw decodedOverrideConfig; } - decodedOverrides.push({ ...override, config: deepKeyIntersect(decodedOverrideConfig, override.config || {}) }); + decodedOverrides.push({ + ...override, + config: deepKeyIntersect(decodedOverrideConfig, override.config || {}), + }); } return { diff --git a/src/utils.ts b/src/utils.ts index 029e8037..832484b9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -574,11 +574,19 @@ export class UnknownUser { } } +export function isObjectLiteral(obj) { + let deepestPrototype = obj; + while (Object.getPrototypeOf(deepestPrototype) != null) { + deepestPrototype = Object.getPrototypeOf(deepestPrototype); + } + return Object.getPrototypeOf(obj) === deepestPrototype; +} + export function deepKeyIntersect(obj, keyReference) { const result = {}; for (const [key, value] of Object.entries(obj)) { if (!keyReference.hasOwnProperty(key)) continue; - if (value != null && typeof value === "object" && typeof keyReference[key] === "object") { + if (value != null && typeof value === "object" && typeof keyReference[key] === "object" && isObjectLiteral(value)) { result[key] = deepKeyIntersect(value, keyReference[key]); } else { result[key] = value;