proofs.rs

Partial parsing omits a single zero from the consumed length

Partial parsing omits a single zero from the consumed length

Found in Report #35 v1 · Updated 2026-11-10 01:49 UTC

Description

from_lexical_partial_with_options reports too few consumed bytes for a single zero when the format forbids integer leading zeros.

Prerequisites
  • Rust version: 1.94.1
  • lexical-parse-integer version: 1.0.6
  • Features: format, power-of-two
  • Direct dependency: lexical-util 1.0.7 with format and power-of-two
Test case
use lexical_parse_integer::{FromLexicalWithOptions, Options};
use lexical_util::format::NumberFormatBuilder;

fn main() {
    const FORMAT: u128 = NumberFormatBuilder::new()
        .no_integer_leading_zeros(true).build_strict();
    let result = u8::from_lexical_partial_with_options::<FORMAT>(b"0", &Options::new());
    assert_eq!(result, Ok((0, 1))); // actual: Ok((0, 0))
}
Additional Context

This also occurs with -0, which reports one consumed byte instead of two. Related: https://github.com/Alexhuszagh/rust-lexical/issues/225.

Change history
  1. v1 · created · 2026-11-10 01:49 UTC
    {
      "title": "Partial parsing omits a single zero from the consumed length",
      "body": "## Description\n\n`from_lexical_partial_with_options` reports too few consumed bytes for a single zero when the format forbids integer leading zeros.\n\n## Prerequisites\n\n- Rust version: 1.94.1\n- lexical-parse-integer version: 1.0.6\n- Features: `format`, `power-of-two`\n- Direct dependency: `lexical-util` 1.0.7 with `format` and `power-of-two`\n\n## Test case\n\n```rust\nuse lexical_parse_integer::{FromLexicalWithOptions, Options};\nuse lexical_util::format::NumberFormatBuilder;\n\nfn main() {\n    const FORMAT: u128 = NumberFormatBuilder::new()\n        .no_integer_leading_zeros(true).build_strict();\n    let result = u8::from_lexical_partial_with_options::<FORMAT>(b\"0\", &Options::new());\n    assert_eq!(result, Ok((0, 1))); // actual: Ok((0, 0))\n}\n```\n\n## Additional Context\n\nThis also occurs with `-0`, which reports one consumed byte instead of two. Related: https://github.com/Alexhuszagh/rust-lexical/issues/225.",
      "validity": "reported",
      "upstream_status": "not_reported"
    }

Read and join the discussion on the report →