You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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.
Activity
neilconway commentedon Aug 21, 2026
take
Lstarsky0 commentedon Aug 23, 2026
This and #10790 are the same line.
parse_e_notationends its validation withexp == 0is standing in for "the mantissa was empty", and it is neither necessary nor sufficient:"0e0"has a mantissa, butparse_decimal's digit arm doesif digits == 0 && *b == b'0' { continue; }, so a literal zero never incrementsdigits. All three terms are zero and the guard fires. That is this issue."e5"has no mantissa, butexpis 5, so the guard does not fire. That isparse_decimalallows invalid inputse5and-#10790.Measured on
mainwithparse_decimal::<Decimal128Type>(input, 10, 2):"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 ofparse_decimal, which only inspectsbs.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.digitscannot answer the question it is being asked here, because the leading-zerocontinueis what makes it a count of significant digits in the first place.Consolidate string-to-decimal parsing into a single code path
fix: Consolidate string-to-decimal parsing into a single code path (#…
fix: Consolidate string-to-decimal parsing into a single code path (a…
fix: Consolidate string-to-decimal parsing into a single code path (a…
fix: Consolidate string-to-decimal parsing into a single code path (a…