fix(router-core): preserve string search params that don't survive JSON.parse numeric round-trip#7652
Conversation
…ON.parse numeric round-trip parseSearchWith(JSON.parse) destructively coerced any search-param string whose raw value was a valid JSON number. Examples: '662E41' (hex/auth code) → 6.62e+43 (irreversible, lossy) '723421968459640832' → 723421968459640800 (precision loss) The issue: String(6.62e+43) !== '662E41', so the original string cannot be recovered after the conversion. Fix: after JSON.parse succeeds, if the result is a number and String(result) does not equal the original string, skip the assignment and keep the original string. Lossless numeric conversions (e.g. '123' → 123) are unaffected. Fixes TanStack#7650
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthrough
ChangesparseSearchWith Numeric Round-Trip Guard
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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. Comment |
Bug
parseSearchWith(JSON.parse)destructively coerces search-param strings whose raw value happens to be valid JSON scientific notation or a large integer:The root cause:
JSON.parse('662E41')succeeds (it is valid JSON scientific notation: 662 × 10⁴¹), butString(6.62e+43) !== '662E41', so the original string is irrecoverably destroyed beforevalidateSearchever runs.Fixes #7650.
Fix
Add a numeric round-trip guard in
parseSearchWith: afterparser(value)returns a number, only accept it whenString(parsed) === value. If the round-trip fails, the original string is kept instead.Lossless cases like
'123' → 123(whereString(123) === '123') are unaffected.The fix is purely additive — no existing tests needed editing.
Verification
Test Files 1 passed (1)
Tests 41 passed (41) — 40 original + 1 new
Summary by CodeRabbit
Bug Fixes