Skip to content

Preserve integers larger than MAX_SAFE_INTEGER in the doc editor - #1545

Open
apoorva-01 wants to merge 1 commit into
apache:mainfrom
apoorva-01:6008-Preserve-large-integers-in-doc-editor
Open

Preserve integers larger than MAX_SAFE_INTEGER in the doc editor#1545
apoorva-01 wants to merge 1 commit into
apache:mainfrom
apoorva-01:6008-Preserve-large-integers-in-doc-editor

Conversation

@apoorva-01

@apoorva-01 apoorva-01 commented Jul 8, 2026

Copy link
Copy Markdown

Overview

Save a document with an integer bigger than Number.MAX_SAFE_INTEGER and it comes back rounded: 9223372036854775807 turns into 9223372036854776000. CouchDB keeps the number fine, but the editor runs the doc through native JSON.parse/JSON.stringify, which can't hold ints that big. It rounds on load, on display, on re-parse, and on save.

I added a small helper (app/core/lossless-json.js) around lossless-json (MIT) that keeps oversized ints as LosslessNumber and leaves normal numbers alone, then used it at those spots in the Doc model and the editor.

I kept it scoped to the doc editor. The same rounding can happen anywhere the app parses JSON, so the wider option is to do this in the core ajax layer instead. Bigger blast radius, so I left it out for now. Happy to go that way if you'd rather. (M-Tesla sketched basically this approach on the issue but hadn't opened a PR.)

Testing recommendations

Add a doc like {"_id": "big", "hugeNumber": 9223372036854775807}, open it in Fauxton, save, fetch again. Should be unchanged. npm run jest and npm run stylecheck are green (744 tests); there's a round-trip test that checks the save body keeps the full number, and it fails without the fix.

GitHub issue number

Fixes apache/couchdb#6008

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • Documentation reflects the changes (no docs affected);
  • Update rebar.config.script with the correct tag once a new Fauxton release is made (release step).

Saving a document with an integer past Number.MAX_SAFE_INTEGER rounded
it (9223372036854775807 became 9223372036854776000) because the editor
ran the document through native JSON.parse/stringify. Use lossless-json
for the document's parse and serialize so the value round-trips intact.

Fixes apache/couchdb#6008
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.

[Bug]: Fauxton silently corrupts integers larger than Number.MAX_SAFE_INTEGER

1 participant