Skip to content

arbitrary_precision: keep the sign of -0 - #1346

Merged
dtolnay merged 1 commit into
serde-rs:masterfrom
yuxi-liu-wired:pr/ap-negative-zero
Oct 10, 2026
Merged

dtolnay merged 1 commit into
serde-rs:masterfrom
yuxi-liu-wired:pr/ap-negative-zero

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown

Keep the sign of -0 in Value with arbitrary_precision

Without arbitrary_precision the integer literal -0 deserializes to
the float -0.0, so a Value keeps the sign. With the feature,
parse_any_number turned every integer that fits an i64 into
ParserNumber::I64 (d541381), and "-0".parse::<i64>() is 0, so the
sign was lost:

from_str::<Value>("-0")?            Number(0)    (should be -0)
to_string(&from_str::<Value>("[-0]")?)   "[0]"
from_value::<f64>(from_str("-0")?)  0.0          (from_str::<f64> gives -0.0)

-0 now stays in the textual representation, so it is written back as
-0 and converts to -0.0, matching the behaviour without the feature
and test_parse_negative_zero.

Test: test_negative_zero_value (fails before this change with
--features arbitrary_precision). Suite passes with no features,
arbitrary_precision, +raw_value, +preserve_order,float_roundtrip, and
raw_value,preserve_order.

Testing

Each commit adds a regression test that fails before the change. The full test suite passes and
cargo fmt --check is clean on the changed files.

Found with a differential fuzzer comparing serde_json, simd-json, sonic-rs and jiter.

Without `arbitrary_precision` the integer literal `-0` deserializes to
the float -0.0, so a `Value` keeps the sign. With the feature,
`parse_any_number` turned every integer that fits an i64 into
`ParserNumber::I64` (d541381), and `"-0".parse::<i64>()` is 0, so the
sign was lost:

    from_str::<Value>("-0")?            Number(0)    (should be -0)
    to_string(&from_str::<Value>("[-0]")?)   "[0]"
    from_value::<f64>(from_str("-0")?)  0.0          (from_str::<f64> gives -0.0)

`-0` now stays in the textual representation, so it is written back as
`-0` and converts to -0.0, matching the behaviour without the feature
and `test_parse_negative_zero`.

Test: `test_negative_zero_value` (fails before this change with
`--features arbitrary_precision`). Suite passes with no features,
arbitrary_precision, +raw_value, +preserve_order,float_roundtrip, and
raw_value,preserve_order.

Found by a differential fuzzer (serde_json, simd-json, sonic-rs, jiter).

@dtolnay dtolnay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@dtolnay
dtolnay merged commit 76e44e2 into serde-rs:master Oct 10, 2026
16 checks passed
dadezzz pushed a commit to dadezzz/kube-dns-rs that referenced this pull request Oct 12, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [serde_json](https://github.com/serde-rs/json) | dependencies | patch | `1.0.151` → `1.0.152` |

---

### Release Notes

<details>
<summary>serde-rs/json (serde_json)</summary>

### [`v1.0.152`](https://github.com/serde-rs/json/releases/tag/v1.0.152)

[Compare Source](serde-rs/json@v1.0.151...v1.0.152)

- Preserve sign of `-0` in arbitrary_precision mode ([#&#8203;1346](serde-rs/json#1346), thanks [@&#8203;yuxi-liu-wired](https://github.com/yuxi-liu-wired))
- Fix comparison of large non-integer values with f32::INFINITY ([#&#8203;1347](serde-rs/json#1347), thanks [@&#8203;yuxi-liu-wired](https://github.com/yuxi-liu-wired))

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNDkuMSIsInVwZGF0ZWRJblZlciI6IjQ0LjE0OS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
github-actions Bot pushed a commit to modify-dev/harbor that referenced this pull request Oct 20, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [serde_json](https://github.com/serde-rs/json) | dependencies | patch | `1.0.151` → `1.0.154` |

---

> ⚠️ **Warning**
>
> Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/99) for more information.

---

### Release Notes

<details>
<summary>serde-rs/json (serde_json)</summary>

### [`v1.0.154`](https://github.com/serde-rs/json/releases/tag/v1.0.154)

[Compare Source](serde-rs/json@v1.0.153...v1.0.154)

- Support preserve_order in no_std builds ([#&#8203;1333](serde-rs/json#1333), thanks [@&#8203;razmser](https://github.com/razmser))

### [`v1.0.153`](https://github.com/serde-rs/json/releases/tag/v1.0.153)

[Compare Source](serde-rs/json@v1.0.152...v1.0.153)

- Report invalid UTF-8 at the first bad byte ([#&#8203;1345](serde-rs/json#1345), thanks [@&#8203;00200200](https://github.com/00200200))

### [`v1.0.152`](https://github.com/serde-rs/json/releases/tag/v1.0.152)

[Compare Source](serde-rs/json@v1.0.151...v1.0.152)

- Preserve sign of `-0` in arbitrary_precision mode ([#&#8203;1346](serde-rs/json#1346), thanks [@&#8203;yuxi-liu-wired](https://github.com/yuxi-liu-wired))
- Fix comparison of large non-integer values with f32::INFINITY ([#&#8203;1347](serde-rs/json#1347), thanks [@&#8203;yuxi-liu-wired](https://github.com/yuxi-liu-wired))

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - "before 9am on tuesday"
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNjcuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE2Ny4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1934
Reviewed-by: Thomas de Zeeuw <thomas@futo.org>
DamianReeves added a commit to finos/morphir-rust that referenced this pull request Oct 29, 2026
serde_json 1.0.152 preserves the sign of -0 in arbitrary_precision mode
(serde-rs/json#1346), so the YAML reader's -0 is now stored with the
lexeme -0 instead of 0. The invalid_literals test pinned the old,
sign-folding behavior and failed on the rust-patch update to 1.0.154.

The new behavior keeps the source spelling, so assert it, and require
serde_json 1.0.152 in morphir-core so a crates.io build cannot resolve
an older release that folds the sign.

Beads: morphir-x4ep.1

Claude-Session: https://claude.ai/code/session_016vWNpLC7n2Fat4wgyZR75p
DamianReeves added a commit to finos/morphir-rust that referenced this pull request Nov 1, 2026
serde_json 1.0.152 preserves the sign of -0 in arbitrary_precision mode
(serde-rs/json#1346), so the YAML reader's -0 is now stored with the
lexeme -0 instead of 0. The invalid_literals test pinned the old,
sign-folding behavior and failed on the rust-patch update to 1.0.154.

The new behavior keeps the source spelling, so assert it, and require
serde_json 1.0.152 in morphir-core so a crates.io build cannot resolve
an older release that folds the sign.

Beads: morphir-x4ep.1

Claude-Session: https://claude.ai/code/session_016vWNpLC7n2Fat4wgyZR75p
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.

3 participants