diff --git a/components/tidb_query_expr/src/impl_math.rs b/components/tidb_query_expr/src/impl_math.rs index 4cddd5a4a37..d20a4d19f26 100644 --- a/components/tidb_query_expr/src/impl_math.rs +++ b/components/tidb_query_expr/src/impl_math.rs @@ -612,7 +612,7 @@ fn is_valid_base(base: IntWithSign) -> bool { fn extract_num_str(s: &str, from_base: IntWithSign) -> Option<(String, bool)> { let mut iter = s.chars().peekable(); - let head = *iter.peek().unwrap(); + let head = *iter.peek()?; let mut is_neg = false; if head == '+' || head == '-' { is_neg = head == '-'; @@ -1573,6 +1573,7 @@ mod tests { ("16九a", 10, 8, "20"), ("+", 10, 8, "0"), ("-", 10, 8, "0"), + ("", 2, 16, "0"), ]; for (n, f, t, e) in tests { let n = Some(n.as_bytes().to_vec());