Skip to content

parse_decimal rejects 0e0 #10789

Closed
Closed

Description

@neilconway

Describe the bug

0e0 and -0e0 are valid JSON numbers.

To Reproduce

use arrow_array::types::Decimal128Type;
use arrow_cast::parse::parse_decimal;

parse_decimal::<Decimal128Type>("0e0", 10, 2);  // Err: can't parse the string value 0e0 to decimal

Expected behavior

Should parse successfully.

Additional context

No response

Activity

  1. added
    bug
    on Aug 21, 2026
  2. added theissue type on Aug 21, 2026
  3. neilconway commented on Aug 21, 2026

    @neilconway
    ContributorAuthor

    take

  4. Lstarsky0 commented on Aug 23, 2026

    @Lstarsky0
    Contributor

    This and #10790 are the same line.

    parse_e_notation ends its validation with

    if digits == 0 && fractionals == 0 && exp == 0 {
        return Err(...);
    }

    exp == 0 is standing in for "the mantissa was empty", and it is neither necessary nor sufficient:

    • "0e0" has a mantissa, but parse_decimal's digit arm does if digits == 0 && *b == b'0' { continue; }, so a literal zero never increments digits. All three terms are zero and the guard fires. That is this issue.
    • "e5" has no mantissa, but exp is 5, so the guard does not fire. That is parse_decimal allows invalid inputs e5 and - #10790.

    Measured on main with parse_decimal::<Decimal128Type>(input, 10, 2):

    "0e0"  -> Err(can't parse the string value 0e0 to decimal)
    "0E0"  -> Err
    "-0e0" -> Err
    "0e1"  -> Ok(0)
    "e5"   -> Ok(0)
    "E5"   -> Ok(0)
    "1e0"  -> Ok(100)
    

    "0e1" is the one that shows it cleanly: identical to "0e0" in every way that should matter, accepted only because the exponent digit happens to be non-zero.

    For completeness on #10790's other example, "-" is already rejected — but by the check at the top of parse_decimal, which only inspects bs.last(). That is also why "e5" gets as far as it does: its last byte is a digit, so the early gate passes it through.

    So the fix is one flag rather than two patches: track "saw at least one mantissa digit" separately from the significant-digit count, and gate on that instead of on digits == 0 && fractionals == 0 && exp == 0. digits cannot answer the question it is being asked here, because the leading-zero continue is what makes it a count of significant digits in the first place.

  5. added a commit that references this issue on Sep 1, 2026
    70219af
  6. added 3 commits that reference this issue on Sep 18, 2026
    f9eb4aa
    8bac2b6
    e9e1631
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions