Skip to content

Commit 9a82401

Browse files
committed
fix: defensively copy pending edit images
1 parent 9da86b1 commit 9a82401

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/core/webview/PendingEditOperationStore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class PendingEditOperationStore {
2929

3030
this.operations.set(operationId, {
3131
...editData,
32+
images: editData.images ? [...editData.images] : undefined,
3233
timeoutId,
3334
createdAt: Date.now(),
3435
})
@@ -45,7 +46,7 @@ export class PendingEditOperationStore {
4546
return {
4647
messageTs: operation.messageTs,
4748
editedContent: operation.editedContent,
48-
images: operation.images,
49+
images: operation.images ? [...operation.images] : undefined,
4950
messageIndex: operation.messageIndex,
5051
apiConversationHistoryIndex: operation.apiConversationHistoryIndex,
5152
}

src/core/webview/__tests__/PendingEditOperationStore.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ describe("PendingEditOperationStore", () => {
5858
expect(operation).not.toHaveProperty("createdAt")
5959
})
6060

61+
it("protects stored images from external mutation", () => {
62+
const images = ["before.png"]
63+
store.set("op", { ...editData, images })
64+
65+
images.push("input-mutation.png")
66+
const operation = store.get("op")
67+
operation?.images?.push("output-mutation.png")
68+
69+
expect(store.get("op")?.images).toEqual(["before.png"])
70+
})
71+
6172
it("auto-clears after timeoutMs and logs", () => {
6273
store.set("op", editData)
6374

0 commit comments

Comments
 (0)