Update executor.js

This commit is contained in:
2025-12-28 19:47:57 +08:00
committed by GitHub
parent b52738248d
commit 5fe9b2a21c

View File

@@ -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,16 +169,24 @@ 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) {
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;
}
}
}
}
}
return val;
}