From b23e980250d0f7a36315da9b800d680d816aaa68 Mon Sep 17 00:00:00 2001 From: zzj3720 <17165520+zzj3720@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:20:26 +0000 Subject: [PATCH] fix(editor): prototype-polluting assignment (#9606) --- .../block-database/src/utils/block-utils.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/blocksuite/affine/block-database/src/utils/block-utils.ts b/blocksuite/affine/block-database/src/utils/block-utils.ts index 94e8fd0c28..7b5f24eaa5 100644 --- a/blocksuite/affine/block-database/src/utils/block-utils.ts +++ b/blocksuite/affine/block-database/src/utils/block-utils.ts @@ -168,20 +168,30 @@ export function updateCell( rowId: string, cell: Cell ) { - if ( - rowId === '__proto__' || - rowId === 'constructor' || - rowId === 'prototype' - ) { - throw new Error('Invalid rowId'); - } - const hasRow = rowId in model.cells; - if (!hasRow) { - model.cells[rowId] = Object.create(null); - } model.doc.transact(() => { - model.cells[rowId][cell.columnId] = { - columnId: cell.columnId, + const columnId = cell.columnId; + if ( + rowId === '__proto__' || + rowId === 'constructor' || + rowId === 'prototype' + ) { + console.error('Invalid rowId'); + return; + } + if ( + columnId === '__proto__' || + columnId === 'constructor' || + columnId === 'prototype' + ) { + console.error('Invalid columnId'); + return; + } + const hasRow = rowId in model.cells; + if (!hasRow) { + model.cells[rowId] = Object.create(null); + } + model.cells[rowId][columnId] = { + columnId: columnId, value: cell.value, }; });