Skip to content

Commit 79938b2

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

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/FileUtils/AgGridUtils.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@ const _getColTypeFromTypeArray = (typeArray) => {
8787
};
8888

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

95-
const colMeta = cols.map((col) => ({
98+
const colMeta = colsData.map((col) => ({
9699
field: col.field,
97-
type: _getColTypeFromTypeArray(col.type),
100+
type: col.type,
98101
acceptsEmptyFields: col.acceptsEmptyFields ?? col.cellEditorParams?.acceptsEmptyFields ?? false,
99102
colOptions: {
100103
...options,
@@ -115,17 +118,18 @@ const _validateFormat = (rows, hasHeader, cols, options) => {
115118
for (let rowIndex = startIndex; rowIndex < rows.length; rowIndex++) {
116119
const row = rows[rowIndex];
117120
while (row[row.length - 1] === undefined && row.length > knownColsCount) row.pop();
118-
if (row.length !== knownColsCount || row.includes(undefined)) {
121+
122+
if (row.length < knownColsCount && !row.includes(undefined)) {
119123
_forgeColumnsCountError(row, rowIndex + 1, cols, errors);
120-
continue;
121124
}
122125

123126
for (let colIndex = 0; colIndex < knownColsCount; colIndex++) {
124127
const { type, colOptions, acceptsEmptyFields, field } = colMeta[colIndex];
125128
const value = row[colIndex];
126129
if (value === undefined) continue;
127130

128-
const validationResult = ValidationUtils.isValid(value, type, colOptions, acceptsEmptyFields);
131+
const typeStr = Array.isArray(type) ? type[0] : type;
132+
const validationResult = ValidationUtils.isValid(value, typeStr, colOptions, acceptsEmptyFields);
129133
if (validationResult !== true) {
130134
const { summary: errorSummary, context: errorContext } = validationResult;
131135
const errorLoc = `Line ${rowIndex + 1}, Column ${colIndex + 1} ("${field}")`;

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)