fix: prevent precision loss for large integer strings exceeding MAX_SAFE_INTEGER (#152) - #156
guoyangzhen wants to merge 1 commit into
Conversation
|
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 (1)
📝 WalkthroughWalkthroughModified the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
🔗 Linked issue
Closes #152
📝 Description
destr()converts numeric-looking strings to JavaScript Numbers even when they exceedNumber.MAX_SAFE_INTEGER(9007199254740991), causing silent precision loss:This is because
JsonSigRxmatches integers with up to 16 digits (\d{1,16}), andMAX_SAFE_INTEGERis a 16-digit number. Any 16-digit integer ≥ 9007199254740992 gets corrupted.Fix
Reduce the integer digit limit from 16 to 15 in
JsonSigRx:With 15 digits, the maximum matched integer is 999999999999999 (< MAX_SAFE_INTEGER), so all matched integers are safe.
Impact
"9007199254740993.5"still has decimal handling)"9.007e15"still handled)This is technically a behavior change for 16-digit integer strings, but the current behavior is data corruption — returning a string is always preferable to returning an incorrect number.
Summary by CodeRabbit