Skip to content

Commit

Permalink
fix: protect isDraftable against undefined constructor (#969)
Browse files Browse the repository at this point in the history
* protect against undefined constructor

* add test case
  • Loading branch information
BrianHung authored Oct 22, 2022
1 parent 078e523 commit ced4563
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions __tests__/isDraftable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict"
import { isDraftable } from "../src/immer"

test("non-plain object with undefined constructor doesn't error", () => {
const obj = Object.create(Object.create(null))
expect(isDraftable(obj).toBe(true);
})
2 changes: 1 addition & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function isDraftable(value: any): boolean {
isPlainObject(value) ||
Array.isArray(value) ||
!!value[DRAFTABLE] ||
!!value.constructor[DRAFTABLE] ||
!!value.constructor?.[DRAFTABLE] ||
isMap(value) ||
isSet(value)
)
Expand Down

0 comments on commit ced4563

Please sign in to comment.