mirror of
https://github.com/apache/superset.git
synced 2026-06-13 03:29:17 +00:00
Compare commits
2 Commits
fix/chart-
...
fix/ag-gri
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bade51a42a | ||
|
|
ace7f72f29 |
@@ -379,7 +379,23 @@ function simpleFilterToWhereClause(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === FILTER_OPERATORS.IN_RANGE && filterTo !== undefined) {
|
if (type === FILTER_OPERATORS.IN_RANGE && filterTo !== undefined) {
|
||||||
return `${columnName} ${SQL_OPERATORS.BETWEEN} ${value} AND ${filterTo}`;
|
// BETWEEN bounds are interpolated directly into the WHERE clause, so only
|
||||||
|
// accept finite numeric bounds (date ranges are handled separately above).
|
||||||
|
// Numeric strings from serialized filter state are coerced; anything that
|
||||||
|
// isn't a finite number is dropped rather than concatenated as raw SQL.
|
||||||
|
// Reject null/empty bounds explicitly: Number(null) and Number('') both
|
||||||
|
// coerce to 0, which would otherwise produce a misleading BETWEEN ... AND 0.
|
||||||
|
const isCoercibleBound = (bound: FilterValue): boolean =>
|
||||||
|
(typeof bound === 'number' || typeof bound === 'string') && bound !== '';
|
||||||
|
if (!isCoercibleBound(value) || !isCoercibleBound(filterTo)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const from = Number(value);
|
||||||
|
const to = Number(filterTo);
|
||||||
|
if (!Number.isFinite(from) || !Number.isFinite(to)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return `${columnName} ${SQL_OPERATORS.BETWEEN} ${from} AND ${to}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formattedValue = formatValueForOperator(type, value!);
|
const formattedValue = formatValueForOperator(type, value!);
|
||||||
|
|||||||
@@ -771,6 +771,60 @@ describe('agGridFilterConverter', () => {
|
|||||||
// Should reject column names longer than 255 characters
|
// Should reject column names longer than 255 characters
|
||||||
expect(result.simpleFilters).toHaveLength(0);
|
expect(result.simpleFilters).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should drop inRange bounds that are not numeric', () => {
|
||||||
|
const filterModel: AgGridFilterModel = {
|
||||||
|
age: {
|
||||||
|
filterType: 'number',
|
||||||
|
operator: 'AND',
|
||||||
|
condition1: {
|
||||||
|
filterType: 'number',
|
||||||
|
type: 'inRange',
|
||||||
|
filter: '0 AND 1=1--',
|
||||||
|
filterTo: '100',
|
||||||
|
},
|
||||||
|
condition2: {
|
||||||
|
filterType: 'number',
|
||||||
|
type: 'greaterThan',
|
||||||
|
filter: 5,
|
||||||
|
},
|
||||||
|
} as AgGridCompoundFilter,
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = convertAgGridFiltersToSQL(filterModel);
|
||||||
|
|
||||||
|
// The malicious range condition is dropped, so its payload never reaches
|
||||||
|
// the WHERE clause; the sibling numeric condition survives unchanged.
|
||||||
|
expect(result.complexWhere ?? '').not.toContain('1=1');
|
||||||
|
expect(result.complexWhere ?? '').not.toContain('BETWEEN');
|
||||||
|
expect(result.complexWhere).toBe('age > 5');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should keep numeric inRange bounds (including numeric strings)', () => {
|
||||||
|
const filterModel: AgGridFilterModel = {
|
||||||
|
age: {
|
||||||
|
filterType: 'number',
|
||||||
|
operator: 'AND',
|
||||||
|
condition1: {
|
||||||
|
filterType: 'number',
|
||||||
|
type: 'inRange',
|
||||||
|
filter: '18',
|
||||||
|
filterTo: 65,
|
||||||
|
},
|
||||||
|
condition2: {
|
||||||
|
filterType: 'number',
|
||||||
|
type: 'lessThan',
|
||||||
|
filter: 100,
|
||||||
|
},
|
||||||
|
} as AgGridCompoundFilter,
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = convertAgGridFiltersToSQL(filterModel);
|
||||||
|
|
||||||
|
// Assert the full compound clause so the upper bound and the sibling
|
||||||
|
// condition are both validated, not just the BETWEEN fragment.
|
||||||
|
expect(result.complexWhere).toBe('(age BETWEEN 18 AND 65 AND age < 100)');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Edge cases', () => {
|
describe('Edge cases', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user