Skip to content

fix(acl): preserve Number::Int on serde_json round-trip - #15481

Merged
Legend-Master merged 2 commits into
tauri-apps:devfrom
thanhtoantnt:fix/acl-number-int-coerced-to-float
Jun 5, 2026
Merged

Legend-Master merged 2 commits into
tauri-apps:devfrom
thanhtoantnt:fix/acl-number-int-coerced-to-float

Conversation

@thanhtoantnt

Copy link
Copy Markdown
Contributor

closes #15480

What changed

From<serde_json::Value> for Value in crates/tauri-utils/src/acl/value.rs was checking as_f64() before as_i64(). Because serde_json::Number::as_f64() succeeds for any integer that
fits in an f64, every integer JSON number was silently deserialized as Number::Float — the as_i64() branch was never reached for typical values.

The check order is now:

  1. as_i64() → Number::Int(i) — handles all signed integers
  2. as_u64() → Number::Float(u as f64) — u64 values above i64::MAX can't be represented without wrapping, so Float preserves approximate magnitude
  3. as_f64() → Number::Float(f) — genuine floating-point numbers
  4. fallback → Number::Int(0)

This matches serde_json's own visitor convention of preferring integer representations when the number has no decimal component.

Impact

  • ACL scopes that compare integer values (e.g. { "port": 8080 }) now correctly match Number::Int instead of silently failing against Number::Float(8080.0).
  • TOML integers parsed as Number::Int via Fromtoml::Value no longer lose that distinction when passed through serde_json.

@thanhtoantnt
thanhtoantnt requested a review from a team as a code owner June 5, 2026 02:19
From<serde_json::Value> for Value was checking as_f64() first, which
succeeds for any integer that fits in an f64, causing all integer values
to be silently coerced to Number::Float on deserialization.

Fix the check order to prefer as_i64() first, then as_u64() (falling
back to Float for values above i64::MAX to avoid silent wrapping), and
only using as_f64() for genuine floating-point numbers.

Fixes tauri-apps#15480
@thanhtoantnt
thanhtoantnt force-pushed the fix/acl-number-int-coerced-to-float branch from 31712f9 to 52f3d1a Compare June 5, 2026 02:21
serde_json::Value::Null => Value::Null,
serde_json::Value::Bool(b) => Value::Bool(b),
serde_json::Value::Number(n) => Value::Number(if let Some(f) = n.as_f64() {
serde_json::Value::Number(n) => Value::Number(if let Some(i) = n.as_i64() {

@Legend-Master Legend-Master Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lucasfernog do you still remember where is this From<serde_json:Value> for Value impl is used? I can't seem to find any and this conversion implementation depends heavily on how it was used never mind, it's used in migration and capability builder

I think should look into just use serde_json:Value here in v3

Comment thread crates/tauri-utils/src/acl/value.rs Outdated
From<serde_json::Value> for Value was checking as_f64() first, which
succeeds for any integer that fits in an f64, causing all integer values
to be silently coerced to Number::Float on deserialization.

Fix the check order to prefer as_i64() first, then as_u64() (cast to
i64, wrapping for values above i64::MAX), and only using as_f64() for
genuine floating-point numbers.

Fixes tauri-apps#15480
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Package Changes Through 1e67492

There are 5 changes which include tauri-utils with patch, tauri with patch, tauri-bundler with patch, tauri-cli with patch, @tauri-apps/cli with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tauri-utils 2.9.2 2.9.3
tauri-bundler 2.9.2 2.9.3
tauri-runtime 2.11.2 2.11.3
tauri-runtime-wry 2.11.2 2.11.3
tauri-codegen 2.6.2 2.6.3
tauri-macros 2.6.2 2.6.3
tauri-plugin 2.6.2 2.6.3
tauri-build 2.6.2 2.6.3
tauri 2.11.2 2.11.3
@tauri-apps/cli 2.11.2 2.11.3
tauri-cli 2.11.2 2.11.3

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@Legend-Master Legend-Master left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks

@Legend-Master
Legend-Master merged commit 2783e60 into tauri-apps:dev Jun 5, 2026
23 checks passed
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] Number::Int is silently coerced to Number::Float on serde_json round-trip

2 participants