Skip to content

Commit 742cd4b

Browse files
committed
perf: [10196] validate bad_int in the table
perf: [10196] validate bad_int in the table
1 parent f19368b commit 742cd4b

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/FileUtils/AgGridUtils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ const _getColTypeFromTypeArray = (typeArray) => {
8787
};
8888

8989
const _validateFormat = (rows, hasHeader, cols, options) => {
90-
const colsData = cols.map((col) => ({ ...col, type: _getColTypeFromTypeArray(col.type) }));
9190
const errors = [];
92-
const knownColsCount = colsData.length;
91+
const knownColsCount = cols.length;
9392
const startIndex = hasHeader ? 1 : 0;
9493

9594
const colMeta = cols.map((col) => ({
@@ -115,9 +114,9 @@ const _validateFormat = (rows, hasHeader, cols, options) => {
115114
for (let rowIndex = startIndex; rowIndex < rows.length; rowIndex++) {
116115
const row = rows[rowIndex];
117116
while (row[row.length - 1] === undefined && row.length > knownColsCount) row.pop();
117+
118118
if (row.length !== knownColsCount || row.includes(undefined)) {
119119
_forgeColumnsCountError(row, rowIndex + 1, cols, errors);
120-
continue;
121120
}
122121

123122
for (let colIndex = 0; colIndex < knownColsCount; colIndex++) {

src/FileUtils/__test__/AgGridUtils.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,31 @@ describe('parse valid CSV strings', () => {
8383
});
8484
});
8585

86+
describe('regression: invalid number values should trigger validation errors', () => {
87+
const options = { dateFormat: 'dd/MM/yyyy' };
88+
89+
test('should raise error for bad integer value in age column', () => {
90+
const headerCols = AgGridUtils.getFlattenColumnsWithoutGroups(CUSTOMERS_COLS).map((col) => col.field);
91+
92+
const invalidRow = headerCols.map((field) => {
93+
if (field === 'age') return 'bad_int';
94+
if (field === 'birthday') return '03/05/1978';
95+
if (field === 'height') return '1.7';
96+
return '';
97+
});
98+
99+
const csvData = [headerCols, invalidRow];
100+
const csvStr = csvData.map((row) => row.join(',')).join('\n');
101+
102+
const result = AgGridUtils.fromCSV(csvStr, true, CUSTOMERS_COLS, options);
103+
104+
expect(result.error).toBeDefined();
105+
expect(result.error.length).toBeGreaterThan(0);
106+
// ✅ Accept both "incorrect int value" or "type" style summaries
107+
expect(result.error[0].summary.toLowerCase()).toMatch(/(type|incorrect|int)/);
108+
});
109+
});
110+
86111
describe('parse with invalid parameters', () => {
87112
test('missing fields definition', () => {
88113
const res = AgGridUtils.fromCSV('', false, undefined);

0 commit comments

Comments
 (0)