diff --git a/crates/bls/src/lib.rs b/crates/bls/src/lib.rs index ded2222..fec8346 100644 --- a/crates/bls/src/lib.rs +++ b/crates/bls/src/lib.rs @@ -294,9 +294,14 @@ pub fn compare_versions(a: &str, b: &str) -> Ordering { handle_single_char!(ca, cb, a_chars, b_chars, '.'); // Handle digits with numerical comparison. - // We key off of the A character being a digit intentionally as we presume - // this indicates it will be the same at this position. + // If only one string has digits at this position, that string is newer. if ca.is_ascii_digit() || cb.is_ascii_digit() { + if !ca.is_ascii_digit() { + return Ordering::Less; + } + if !cb.is_ascii_digit() { + return Ordering::Greater; + } let result = compare_numeric(&mut a_chars, &mut b_chars); if result != Ordering::Equal { return result; @@ -719,6 +724,14 @@ efi /EFI/fedora/shimx64.efi assert_eq!(compare_versions("", "1"), Ordering::Less); } + #[test] + fn digits_are_newer_than_letters() { + assert_eq!(compare_versions("0", "a"), Ordering::Greater); + assert_eq!(compare_versions("a", "0"), Ordering::Less); + assert_eq!(compare_versions("1.0", "1.a"), Ordering::Greater); + assert_eq!(compare_versions("1.a", "1.0"), Ordering::Less); + } + #[test] fn optional_both_none_equal() { assert_eq!(compare_versions_optional(None, None), Ordering::Equal);