From b09ccaf6b1010024d56d79f7539c5173b48113aa Mon Sep 17 00:00:00 2001 From: Ron Kuslak Date: Sun, 30 Sep 2018 09:14:18 -0500 Subject: [PATCH] Fix comparison of empty string to numeric f64 sort --- src/sort/sort.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/sort/sort.rs b/src/sort/sort.rs index 4f3013f7b..c21802d49 100644 --- a/src/sort/sort.rs +++ b/src/sort/sort.rs @@ -383,11 +383,15 @@ fn permissive_f64_parse(a: &str) -> f64 { // because there's no way to handle both CSV and thousands separators without a new flag. // GNU sort treats "1,234" as "1" in numeric, so maybe it's fine. // GNU sort treats "NaN" as non-number in numeric, so it needs special care. - let sa: &str = a.split_whitespace().next().unwrap(); - match sa.parse::() { - Ok(a) if a.is_nan() => std::f64::NEG_INFINITY, - Ok(a) => a, - Err(_) => std::f64::NEG_INFINITY, + match a.split_whitespace().next() { + None => std::f64::NEG_INFINITY, + Some(sa) => { + match sa.parse::() { + Ok(a) if a.is_nan() => std::f64::NEG_INFINITY, + Ok(a) => a, + Err(_) => std::f64::NEG_INFINITY, + } + } } }