Skip to content
Myr

fix: patching maps failed when using number keys (#1025)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Marco Schumacher · committed by GitHub · parent 082eecd · Browse files · 2 files+23 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+23 added−1 removed

  • tests:+18 added−0 removed
  • other:+5 added−1 removed

2 files+23 added−1 removed

modified:__tests__/patch.js+18 added
212 unmodified lines
213 ]214 )215})216217describe("simple assignment - 8", () => {218 runPatchTest(219 new Map([[0, new Map([[1, 4]])]]),220 d => {221 d.get(0).set(1, 5)222 d.get(0).set(2, 6)223 },224 [225 {op: "replace", path: [0, 1], value: 5},226 {op: "add", path: [0, 2], value: 6}227 ],228 [229 {op: "replace", path: [0, 1], value: 4},230 {op: "remove", path: [0, 2]}231 ]232 )233})234235describe("delete 1", () => {236 runPatchTest(237 {x: {y: 4}},238 d => {
1209 unmodified lines
modified:src/plugins/patches.ts+5 added-1 removed
205 unmodified lines
206207 let base: any = draft208 for (let i = 0; i < path.length - 1; i++) {209 const parentType = getArchtype(base)210 const p = "" + path[i]210 let p = path[i]211 if (typeof p !== "string" && typeof p !== "number") {212 p = "" + p213 }214215 // See #738, avoid prototype pollution216 if (217 (parentType === Archtype.Object || parentType === Archtype.Array) &&218 (p === "__proto__" || p === "constructor")
87 unmodified lines