From 5fe9b2a21cfd827e467960bc3f305998a1c3443a Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 28 Dec 2025 19:47:57 +0800 Subject: [PATCH] Update executor.js --- core/table-system/executor.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/core/table-system/executor.js b/core/table-system/executor.js index 50582c2..349959c 100644 --- a/core/table-system/executor.js +++ b/core/table-system/executor.js @@ -5,6 +5,13 @@ function insertRow(state, tableIndex, data) { log(`AI指令错误:尝试在不存在的表格索引 ${tableIndex} 中插入行。`, 'error'); return { state, changes: [] }; } + + // 【安全检查】确保 data 是对象 + if (typeof data !== 'object' || data === null) { + log(`AI指令错误:insertRow 的 data 参数必须是对象,实际收到: ${typeof data} (${data})`, 'error'); + return { state, changes: [] }; + } + const table = state[tableIndex]; const colCount = table.headers.length; const newRow = Array(colCount).fill(''); @@ -28,6 +35,12 @@ function updateRow(state, tableIndex, rowIndex, data) { return { state, changes: [] }; } + // 【安全检查】确保 data 是对象 + if (typeof data !== 'object' || data === null) { + log(`AI指令错误:updateRow 的 data 参数必须是对象,实际收到: ${typeof data} (${data})`, 'error'); + return { state, changes: [] }; + } + const table = state[tableIndex]; if (rowIndex >= table.rows.length) { @@ -156,13 +169,21 @@ function parseValue(val) { try { return JSON.parse(val); } catch (e) { + let fixedKeys = val.replace(/([{,]\s*)(\d+)(\s*:)/g, '$1"$2"$3'); try { - let fixedVal = val.replace(/([{,]\s*)(\d+)(\s*:)/g, '$1"$2"$3'); - fixedVal = fixedVal.replace(/'/g, '"'); - - return JSON.parse(fixedVal); + return JSON.parse(fixedKeys); } catch (e2) { - return val; + let fixedQuotes = fixedKeys.replace(/'/g, '"'); + try { + return JSON.parse(fixedQuotes); + } catch (e3) { + let fixedAllKeys = val.replace(/([{,]\s*)([a-zA-Z0-9_]+)(\s*:)/g, '$1"$2"$3'); + try { + return JSON.parse(fixedAllKeys); + } catch (e4) { + return val; + } + } } } }