Commit 56ab473
authored
fix(table-core): guard Array.isArray before index access in range filter autoRemove (TanStack#6394)
* fix(table-core): guard Array.isArray before index access in range filter autoRemove
`filterFn_between`, `filterFn_betweenInclusive`, and
`filterFn_inNumberRange` shared an `autoRemove` that did
`testFalsy(val[0]) && testFalsy(val[1])`. When a scalar value such as
`99` was passed instead of a `[min, max]` tuple, `val[0]` and
`val[1]` were both `undefined`, so the condition evaluated to
`true && true` and the filter was silently auto-removed.
Numeric columns default to `inNumberRange` via
`column_getAutoFilterFn`, so calling `col.setColumnFilter(99)` on a
numeric column discarded the filter before the row scan even ran.
Wrap the index checks in `Array.isArray(val) &&`. The leading
`testFalsy(val)` still handles `undefined`, `null`, `0`, and
`''`. Behavior of the existing array-tuple cases is unchanged because
`Array.isArray` is true and short-circuits to the same boolean.
Closes TanStack#6353
* test(filterFns): assert empty-string scalar IS auto-removed
The previous regression test for TanStack#6353 bundled the non-empty scalar
case (autoRemove(99) and autoRemove(0)) with an empty-string
expectation (autoRemove('')). testFalsy treats '' as falsy, so the
leading testFalsy(val) branch correctly returns true for '' - the
Array.isArray guard added in 0041efb is intentionally additive and
not meant to override that behavior.
Split the assertion: the non-empty scalar test now stands alone with
just autoRemove(99) and autoRemove(0); the empty-string behavior is
covered by a separate explicit assertion (expect(autoRemove(''))).toBe(true))
Vitest run:
Test Files 1 passed (1)
Tests 73 passed (73)
Signed-off-by: sanjibani <18418553+sanjibani@users.noreply.github.com>
---------
Signed-off-by: sanjibani <18418553+sanjibani@users.noreply.github.com>
Co-authored-by: sanjibani <18418553+sanjibani@users.noreply.github.com>
Co-authored-by: JSap09141 parent efdeeb9 commit 56ab473
2 files changed
Lines changed: 55 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
| 250 | + | |
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
| |||
285 | 286 | | |
286 | 287 | | |
287 | 288 | | |
288 | | - | |
| 289 | + | |
| 290 | + | |
289 | 291 | | |
290 | 292 | | |
291 | 293 | | |
| |||
329 | 331 | | |
330 | 332 | | |
331 | 333 | | |
332 | | - | |
| 334 | + | |
| 335 | + | |
333 | 336 | | |
334 | 337 | | |
335 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
596 | 602 | | |
597 | 603 | | |
598 | 604 | | |
| |||
617 | 623 | | |
618 | 624 | | |
619 | 625 | | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
620 | 669 | | |
621 | 670 | | |
622 | 671 | | |
| |||
0 commit comments