Skip to content

修复Json美化工具,原始 JSON 中包含嵌套 JSON 时整数精度丢失问题#546

Merged
zxlie merged 3 commits intozxlie:masterfrom
wjfz:master
Apr 14, 2026
Merged

修复Json美化工具,原始 JSON 中包含嵌套 JSON 时整数精度丢失问题#546
zxlie merged 3 commits intozxlie:masterfrom
wjfz:master

Conversation

@wjfz
Copy link
Copy Markdown
Contributor

@wjfz wjfz commented Mar 6, 2026

修复前:
Clipboard_Screenshot_1772791163

修复后:
Clipboard_Screenshot_1772790586

{
  "body":{
    "data":{
      "account_id":1401004938049356981
    }
  },
  "rawBody":"{\"data\":{\"account_id\":1401004938049356981}"
}

Copilot AI and others added 3 commits March 6, 2026 09:20
…d escaped JSON strings

The regex that marks large integers (16+ digits) for BigInt handling was blindly
replacing all matches, including numbers inside JSON string values. This corrupted
the JSON structure (inserting unescaped quotes inside strings), causing JSON.parse
to fail and fall back to eval-based parsing which loses integer precision.

Fix: Add an offset-based string context check (consistent with json-worker.js and
format-lib.js) that tracks whether the match position is inside a JSON string by
scanning for unescaped quote characters. Numbers inside strings are left untouched.

Co-authored-by: wjfz <3372236+wjfz@users.noreply.github.com>
Fix BigInt precision loss in parseWithBigInt for JSON with nested escaped JSON strings
@zxlie zxlie merged commit b0d0d44 into zxlie:master Apr 14, 2026
@zxlie
Copy link
Copy Markdown
Owner

zxlie commented Apr 14, 2026

感谢 @wjfz 提交的修复!

这个改动非常精准——通过 offset 参数回溯检测当前匹配位置是否在 JSON 字符串内部,避免了对嵌套转义 JSON 中大整数的误标记。逻辑清晰、改动最小化,且不影响正常的 BigInt 场景。

已合并,再次感谢你的贡献!🎉

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.

3 participants