Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions __tests__/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,24 @@ describe("simple assignment - 7", () => {
)
})

describe("simple assignment - 8", () => {
runPatchTest(
new Map([[0, new Map([[1, 4]])]]),
d => {
d.get(0).set(1, 5)
d.get(0).set(2, 6)
},
[
{op: "replace", path: [0, 1], value: 5},
{op: "add", path: [0, 2], value: 6}
],
[
{op: "replace", path: [0, 1], value: 4},
{op: "remove", path: [0, 2]}
]
)
})

describe("delete 1", () => {
runPatchTest(
{x: {y: 4}},
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ export function enablePatches() {
let base: any = draft
for (let i = 0; i < path.length - 1; i++) {
const parentType = getArchtype(base)
const p = "" + path[i]
let p = path[i]
if (typeof p !== "string" && typeof p !== "number") {
p = "" + p
}

// See #738, avoid prototype pollution
if (
(parentType === Archtype.Object || parentType === Archtype.Array) &&
Expand Down