Skip to content

Keep the source spelling of floats copied into an editable document - #6123

Open
atharva-potdar wants to merge 1 commit into
nlohmann:developfrom
atharva-potdar:fix/view-copied-float-source-spelling
Open

atharva-potdar wants to merge 1 commit into
nlohmann:developfrom
atharva-potdar:fix/view-copied-float-source-spelling

Conversation

@atharva-potdar

@atharva-potdar atharva-potdar commented Nov 13, 2026 •

Copy link
Copy Markdown

Fixes #6113.

An edit that copies a float from a view of another document stores the source token verbatim in the edit arena and marks the node as edited. dump(number_format::source) copied only tokens outside the edit arena, so the copied float was written in the shortest form while number_token() and the saved image kept the source token. Consequently, load(doc.save()).dump(source) differed from doc.dump(source), although save() writes the current state.

Copy an edited float token as well, except nan, inf, and -inf, which remain null. Tokens written by set() or push_back() already contain the BasicJsonType::dump() form, so their output does not change. An integer copied from another document is still rebuilt in canonical form, so -0 becomes 0.

Add a regression test for a float copied from another document and update editing.md to state that a copied number keeps its spelling.

  • Changes described in detail, both the what and why.
  • Existing issue referenced (Fixes #6113).
  • OSS-Fuzz issue - not applicable.
  • Test added for every new line; changed-line coverage verified locally.
  • Documentation updated.
  • Source code amalgamated with make amalgamate.

An edit that copies a float from a view of another document stores the
source token verbatim in the edit arena and marks the node as edited.
dump(number_format::source) copied only tokens outside the edit arena, so
the copied float was written in the shortest form while number_token() and
the saved image kept the source token. load(doc.save()).dump(source) thus
differed from doc.dump(source), although save() writes the current state.

Copy an edited float token as well, except nan, inf and -inf, which remain
null. Tokens written by set() or push_back() already contain the
BasicJsonType::dump() form, so their output does not change. Add a
regression test for a float copied from another document and update
editing.md to state that a copied number keeps its spelling. An integer
copied from another document is still rebuilt in canonical form, so -0
becomes 0.

Fixes nlohmann#6113.

Signed-off-by: atharva-potdar <atharvapotdar07@gmail.com>
@github-actions github-actions Bot added documentation M tests aspect: json_view json_document, json_view (zero-copy view) labels Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aspect: json_view json_document, json_view (zero-copy view) documentation M tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

json_view: dump(number_format::source) writes a float copied from another document in shortest form, but its saved image keeps the source spelling

1 participant