Explorar el Código

fix(common): Handle edge case in serializing null prototype objects

Michael Bromley hace 3 años
padre
commit
02249fbf3d
Se han modificado 1 ficheros con 3 adiciones y 1 borrados
  1. 3 1
      packages/common/src/shared-utils.ts

+ 3 - 1
packages/common/src/shared-utils.ts

@@ -24,7 +24,9 @@ export function isObject(item: any): item is object {
 }
 
 export function isClassInstance(item: any): boolean {
-    return isObject(item) && item.constructor.name !== 'Object';
+    // Even if item is an object, it might not have a constructor as in the
+    // case when it is a null-prototype object, i.e. created using `Object.create(null)`.
+    return isObject(item) && item.constructor && item.constructor.name !== 'Object';
 }
 
 type NumericPropsOf<T> = {