fix: 严格校验批量失败行号

This commit is contained in:
2026-08-17 21:39:03 +08:00
parent dc6341d24e
commit 98f573fab4
2 changed files with 29 additions and 0 deletions

View File

@@ -326,6 +326,28 @@ describe('batch-form-model', () => {
);
});
it('keeps every row when a runtime row index is not a number', () => {
const rows = [createBatchRow()];
const result = applyBatchResult(rows, {
successCount: 0,
failureCount: 1,
failures: [
{
clientKey: 'unknown-key',
rowIndex: '1' as unknown as number,
errorCode: 'INVALID_INDEX',
message: '行号类型错误',
},
],
});
const generalError = '批量保存结果无法匹配,请核对后重试';
expect(result.rows).toEqual(rows);
expect(result.rowErrors).toEqual(
new Map(rows.map((row) => [row.clientKey, generalError])),
);
});
it('returns no rows or errors when every row succeeds', () => {
const result = applyBatchResult([createBatchRow()], {
successCount: 1,

View File

@@ -111,6 +111,13 @@ export function applyBatchResult(
const failedClientKeys = new Set<string>();
const rowErrors = new Map<string, string>();
for (const failure of result.failures) {
if (
!Number.isInteger(failure.rowIndex) ||
failure.rowIndex < 1 ||
failure.rowIndex > rows.length
) {
return unsafeResult();
}
const rowByKey = rowByClientKey.get(failure.clientKey);
const rowByIndex = rows[failure.rowIndex - 1];
if (