Skip to content
Source
Sign inSign up
TanStack/table

fix(table-core): guard range filters against non-array values #6602

Openhnton2(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/6602/headopened

Showing 3 changed files with 128 additions and 3 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/guard-range-filter-tuple.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/table-core': patch
+---
+​
+Guard `resolveFilterValue` in `inNumberRange` and `inDateRange` against filter values that are not arrays. Previously a string was destructured per character (`'30'` became the range `[0, 3]`, filtering silently wrong) and a number, boolean or `Date` threw `TypeError: val is not iterable`. Such values now leave the range fully open and warn in development.
39 additions and 2 deletionspackages/table-core/src/features/column-filtering/filterFns.tsModified
View file
@@ -280,7 +280,9 @@
* Filter values are normalized so blank endpoints become open-ended and
* reversed endpoints are swapped. Only real numbers can fall inside the
* range: non-numeric row values (`null`, `undefined`, strings, booleans)
- * never match.
+ * never match. A filter value that is not an array leaves the range fully
+ * open and warns in development, instead of being split per character or
+ * throwing.
export const filterFn_inNumberRange = constructFilterFn({
filter: (dataValue: number, filterValue: [number, number]) => {
@@ -294,6 +296,10 @@
return dataValue >= min && dataValue <= max
resolveFilterValue: (val: [any, any]) => {
+ if (!isRangeArray(val, 'inNumberRange')) {
+ return [-Infinity, Infinity] as const
+ }
+​
const [unsafeMin, unsafeMax] = val
​