فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(A02): reject damaged CSV encoding and absent source tables
davoodmehraban89 committed
Oct 19, 2026 at 01:17 UTC
20b126c7c81dae7a0e93056ea7fa606d4f0a59b3
1 file changed
+5
-1
src/core/HolooDelimitedExportPreflight.mjs
+5
-1
@@ -36,6 +36,9 @@ export function parseStrictDelimitedRows(text, { delimiter = ',' } = {}) {
36
throw new RangeError('CSV_INVALID_SIZE');
37
if (!SEPARATORS.has(delimiter)) reject('CSV_UNSUPPORTED_DELIMITER');
38
if (!text.length) reject('CSV_EMPTY_SOURCE');
39
+ // Embedded NUL and non-leading BOM indicate a damaged or mixed-encoding export.
40
+ if (text.includes('\0')) reject('CSV_NUL_BYTE');
41
+ if (text.slice(1).includes('\uFEFF')) reject('CSV_EMBEDDED_BOM');
42
const rows = [];
43
let record = [], cell = '', quoted = false, afterQuote = false, begun = false;
44
// Include the final sentinel newline to flush a possibly unterminated row.
@@ -86,7 +89,7 @@ export function parseStrictDelimitedRows(text, { delimiter = ',' } = {}) {
89
if (record.length || cell || afterQuote || begun) submitRecord();
90
if (!rows.length) reject('CSV_NO_HEADER');
91
const headers = rows.shift().map(x => x.trim());
89
- if (!headers.length || headers.some(x => !x) ||
92
+ if (!headers.length || headers.some(x => !x || /[\u0001-\u001F\u007F]/.test(x)) ||
93
new Set(headers).size !== headers.length) reject('CSV_INVALID_HEADER');
94
if (rows.some(row => row.length !== headers.length))
95
reject('CSV_ROW_WIDTH_MISMATCH');
@@ -178,6 +181,7 @@ export function previewHolooDelimitedExport({
181
// financial source table and falsely suggest the extract was inspected.
182
if (Object.keys(mappings).some(table => !Object.hasOwn(tables, table)))
183
reject('CSV_MAPPING_WITHOUT_SOURCE_TABLE');
184
+ if (!Object.keys(tables).length) reject('CSV_NO_SOURCE_TABLES');
185
const datasets = {};
186
for (const [table, item] of Object.entries(tables)) {
187
if (!validMap(item) || typeof item.text !== 'string' ||