fix(table-core): guard range filters against non-array values #6602
Openhnton2(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/6602/headopened - packages/table-core/src/features/column-filtering/filterFns.ts line 494Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -468,3 +481,14 @@468481 return val === undefined || val === null || val === ''469482 }470483484+/**485+ * Guards a range filter value before it is destructured.486+ *487+ * `[any, any]` only exists at compile time: at runtime `setFilterValue()` can488+ * be handed anything. Destructuring a string splits it per character (`'30'`489+ * becomes `'3'` and `'0'`, a range nothing asked for), and destructuring a490+ * number, boolean or `Date` throws. `autoRemove` does not catch either case,491+ * since it only drops falsy values and fully blank tuples.492+ */493+function isRangeTuple(val: any, filterFnName: string): val is [any, any] {494+ if (Array.isArray(val)) {
hnton2(GitHub profile, opens in a new tab) changed the title
- @@ -468,3 +480,20 @@468480 return val === undefined || val === null || val === ''469481 }470482483+/**484+ * Guards a range filter value before it is destructured.485+ *486+ * `[any, any]` only exists at compile time: at runtime `setFilterValue()` can487+ * be handed anything. Destructuring a string splits it per character (`'30'`488+ * becomes `'3'` and `'0'`, a range nothing asked for), and destructuring a489+ * number, boolean or `Date` throws. `autoRemove` does not catch either case,490+ * since it only drops falsy values and fully blank tuples. Arrays of any491+ * length pass through to the existing endpoint handling unchanged.492+ */493+function isRangeArray(val: any, filterFnName: string): val is Array<any> {494+ if (Array.isArray(val)) {495+ return true496+ }497+498+ if (499+ typeof process !== 'undefined' &&
- @@ -468,3 +480,19 @@468480 return val === undefined || val === null || val === ''469481 }470482483+/**484+ * Guards a range filter value before it is destructured.485+ *486+ * `[any, any]` only exists at compile time: at runtime `setFilterValue()` can487+ * be handed anything. Destructuring a string splits it per character (`'30'`488+ * becomes `'3'` and `'0'`, a range nothing asked for), and destructuring a489+ * number, boolean or `Date` throws. `autoRemove` does not catch either case,490+ * since it only drops falsy values and fully blank tuples. Arrays of any491+ * length pass through to the existing endpoint handling unchanged.492+ */493+function isRangeArray(val: any, filterFnName: string): val is Array<any> {494+ if (Array.isArray(val)) {495+ return true496+ }497+498+ if (process.env.NODE_ENV === 'development') {
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough#
The number and date range filter resolvers now check filter values before processing endpoints. Non-array values resolve to open ranges and produce a development warning. Tests cover malformed values, valid tuples, and cleanup of environment stubs and mocks.
Changes#
Range filter input guards
packages/table-core/src/features/column-filtering/filterFns.ts,packages/table-core/tests/unit/fns/filterFns.test.ts,.changeset/guard-range-filter-tuple.mdPriority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Low
Suggested reviewers:
kevinvandyMerge Risk: 🟡 Moderate · up to
dd154Malformed range filters can still abort filtering in process-free browsers. Make the warning check safe before merging while preserving development warnings and existing array behavior.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
dd154The change remains confined to table filtering, with no demonstrated authorization or privilege change. However, malformed filter values can still interrupt filtering in environments without process, including strings that previously resolved without throwing. The published output was unavailable to confirm the effective behavior.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share