3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-18 07:35:02 +00:00

Fix for non-object-literals in deepKeyIntersect

This commit is contained in:
Dragory 2019-08-04 16:47:42 +03:00
parent 5e7c70dbf1
commit 6fa0a55b28
2 changed files with 13 additions and 2 deletions

View file

@ -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;