This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new c3899cea0cd Fix integer parsing of empty strings (#5504) (#5505)
c3899cea0cd is described below

commit c3899cea0cda046c2c635d6a2f75baee8ee1ea99
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Fri Mar 15 06:17:09 2024 +1300

    Fix integer parsing of empty strings (#5504) (#5505)
---
 arrow-cast/src/parse.rs | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/arrow-cast/src/parse.rs b/arrow-cast/src/parse.rs
index 7f23526142c..afa00f17629 100644
--- a/arrow-cast/src/parse.rs
+++ b/arrow-cast/src/parse.rs
@@ -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(),
                 ) {
@@ -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);
+    }
 }

Reply via email to