Skip to content

fix(safe-json): parse negative BigInts#274

Open
bramcohen wants to merge 2 commits into
WalletConnect:masterfrom
bramcohen:fix/safe-json-negative-bigint
Open

fix(safe-json): parse negative BigInts#274
bramcohen wants to merge 2 commits into
WalletConnect:masterfrom
bramcohen:fix/safe-json-negative-bigint

Conversation

@bramcohen

Copy link
Copy Markdown

Summary

safeJsonStringify emits negative BigInts as "-100n", but safeJsonParse only matched /^\d+n$/, so negatives stayed strings.
Change the reviver to /^-?\d+n$/ and add a round-trip test.

Test plan

  • cd misc/safe-json && npm test (Node 24)

Copilot AI review requested due to automatic review settings July 15, 2026 23:10
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

All contributors have signed the CTA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@bramcohen

Copy link
Copy Markdown
Author

I have read the CTA Document and I hereby sign the CTA

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes @walletconnect/safe-json so safeJsonParse correctly revives negative BigInt values that were serialized in the library’s custom string format (e.g. "-100n"), and adds a test to prevent regressions.

Changes:

  • Update the BigInt reviver pattern in safeJsonParse to accept an optional leading -.
  • Add a round-trip test covering negative BigInt serialization/parsing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
misc/safe-json/src/index.ts Expands the BigInt reviver regex to recognize negative custom BigInt strings.
misc/safe-json/test/index.test.ts Adds a unit test validating negative BigInt round-trip behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread misc/safe-json/src/index.ts Outdated
…maxint

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants