Skip to content

Commit

Permalink
Fix integer parsing of empty strings (#5504) (#5505)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold authored Mar 14, 2024
1 parent d39cf28 commit c3899ce
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions arrow-cast/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ macro_rules! parser_primitive {
($t:ty) => {
impl Parser for $t {
fn parse(string: &str) -> Option<Self::Native> {
if !string.as_bytes().last().is_some_and(|x| x.is_ascii_digit()) {
return None;
}
match atoi::FromRadix10SignedChecked::from_radix_10_signed_checked(
string.as_bytes(),
) {
Expand Down Expand Up @@ -2303,4 +2306,22 @@ mod tests {
assert_eq!(i, result.unwrap());
}
}

#[test]
fn test_parse_empty() {
assert_eq!(Int32Type::parse(""), None);
assert_eq!(Int64Type::parse(""), None);
assert_eq!(UInt32Type::parse(""), None);
assert_eq!(UInt64Type::parse(""), None);
assert_eq!(Float32Type::parse(""), None);
assert_eq!(Float64Type::parse(""), None);
assert_eq!(Int32Type::parse("+"), None);
assert_eq!(Int64Type::parse("+"), None);
assert_eq!(UInt32Type::parse("+"), None);
assert_eq!(UInt64Type::parse("+"), None);
assert_eq!(Float32Type::parse("+"), None);
assert_eq!(Float64Type::parse("+"), None);
assert_eq!(TimestampNanosecondType::parse(""), None);
assert_eq!(Date32Type::parse(""), None);
}
}

0 comments on commit c3899ce

Please sign in to comment.