Wrap unsafe array numbers in RPC responses#2383
Conversation
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (2)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e6642f986
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export function wrapBigNumbersAsStrings(text: string): string { | ||
| return text.replace(/(":\s*)(-?\d+)(\s*[},])/g, (match, p1, p2, p3) => { | ||
| const num = Number(p2); | ||
| return text.replace(/-?\d+(?=\s*[,}\]])/g, (match, offset) => { |
There was a problem hiding this comment.
Avoid rewriting numbers inside JSON strings
Because this regex scans the raw JSON text without tracking whether the match is inside a quoted string, it can now rewrite string contents when an unsafe-looking number is preceded by :, [, or , and followed by ], }, or , within that string. For example, a valid RPC string field like {"logs":["Program log: [9007199254740992]"]} becomes invalid JSON after wrapping, so JSON.parse(wrappedJsonString) will throw for responses containing such log/error/message text.
Useful? React with 👍 / 👎.
Handle unsafe integer values inside JSON arrays when preprocessing RPC responses.
The existing helper only wrapped large object property values, so unsafe integers in arrays could still be parsed as JavaScript numbers and lose precision.