Skip to content

arbitrary_precision: keep the sign of -0 in Number and reject as i128 - #1353

Open
rfanth wants to merge 1 commit into
serde-rs:masterfrom
rfanth:ap-negative-zero-number
Open

rfanth wants to merge 1 commit into
serde-rs:masterfrom
rfanth:ap-negative-zero-number

Conversation

@rfanth

@rfanth rfanth commented Oct 14, 2026 •

Copy link
Copy Markdown

Recently, #1346 made the arbitrary precision parser keep -0 as text, but the sign still gets lost in Number, and in i128. This also fixes from_str::<i128>("-0") which currently returns 0, inconsistent with the <i64> version which returns Err.

let v: Value = from_str("-0")?;   // arb_prec (before -> this PR)  |  default build (before -> this PR)
v.as_i64()                        // Some(0) -> None    |  None  -> None
from_value::<Value>(v)?           // 0       -> -0      |  -0.0  -> -0.0
from_str::<i64>("-0")             // Err     -> Err     |  Err   -> Err
from_str::<i128>("-0")            // Ok(0)   -> Err     |  Ok(0) -> Err (now just like from_str::<i64>)

This fixes do_deserialize_i128's own version of the -0 bug, and four places in number.rs that also suffered from it.

All paths changed have tests added that failed before.

Everything is in arbitrary_precision, except do_deserialize_i128, which is shared and changes from_str::<i128>("-0") in both builds to be Err. This now matches from_str::<i64>("-0") which was already Err, fixing a preexisting bug in the process of fixing -0.

Cargo test and pedantic clippy pass.

Discovered while working on TJSON. I had the previous -0 behavior pinned as a known bug in serde_json, and when #1346 patched part of the problem it made tjson-rs's CI fail. Investigating turned up the remaining holes.

@rfanth
rfanth force-pushed the ap-negative-zero-number branch from ba4f93a to 6fb60f0 Compare October 16, 2026 14:39
@rfanth

rfanth commented Oct 16, 2026 •

Copy link
Copy Markdown
Author

Rebased onto #1355. #1355 made the edit I considered doing here but didn't at first for fear of breaking some longer tagged enums with long decimals, so -0 rather than -0.0 is now possible, and what this PR now produces.

A few tests were slightly changed to check the spelling as well. The PR message and chart were updated to match the current behavior.

Dicklesworthstone added a commit to Dicklesworthstone/fastmcp_rust that referenced this pull request Oct 28, 2026
First test run since 2026-10-05: 1,192 tests executed on the fleet via
rch exec --job.

  fastmcp-core      459 passed, 0 failed              GREEN
  fastmcp-protocol  733 passed, 1 FAILED              RED
  fastmcp-transport not run (cargo stops at the first failing package)

The failure is real and in the campaign's required test set. A wire -0
cancellation ID now survives parsing as -0 while the typed layer still decodes
it to Integer(0), so a test named for lexeme preservation fails.

Cause PROVEN by upstream release notes rather than inferred: serde_json 1.0.152
'Preserve sign of -0 in arbitrary_precision mode (#1346)'. The project pinned
=1.0.151 explicitly FOR its number semantics ('FND-01 ROOT-SERDE-JSON: exact
version + arbitrary_precision for protocol numbers') and dependabot's 59fea33
moved it to =1.0.154, crossing that change. serde-rs/json#1353 documents the
remaining upstream half: the parser keeps -0 as text but the sign is still lost
in Number and i128, which is exactly the split measured here.

Three remedies recorded; I applied none. Making the suite green means deleting
the assertion that states the guarantee (RH-3/RH-1), and reverting the pin
re-masks the gap and re-breaks the FND-01 freeze. A protocol owner chooses.

Same commit 59fea33 also staled the FND-01 input freeze (bd-44sow, bd-hk62x),
so one unreviewed patch bump defeated both mechanisms that should have caught
it, for 9 days.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

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

None yet

Development

Successfully merging this pull request may close these issues.

1 participant