From 5a793bebe888b74e21c6f68dfa05c3ddddf63703 Mon Sep 17 00:00:00 2001 From: John Turner Date: Fri, 14 Nov 2025 23:15:01 +0000 Subject: [PATCH] check if a OR b has leading zeros, and if so, strip and do ascii cmp --- src/atom/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/atom/mod.rs b/src/atom/mod.rs index 97c57f7..d8cb543 100644 --- a/src/atom/mod.rs +++ b/src/atom/mod.rs @@ -293,7 +293,9 @@ impl Ord for VersionNumbers { loop { match (a.next(), b.next()) { - (Some(a), Some(b)) if a.get().starts_with("0") => { + (Some(a), Some(b)) + if a.get().starts_with("0") || b.get().starts_with("0") => + { let a = a.get().trim_end_matches("0"); let b = b.get().trim_end_matches("0"); @@ -765,4 +767,16 @@ mod test { assert_cmp_display!(a, b, Ordering::Less); } + + #[test] + fn test_version_cmp_where_b_has_leading_zeros() { + let a = Version::parser() + .parse_finished(InputIter::new("1.2")) + .unwrap(); + let b = Version::parser() + .parse_finished(InputIter::new("1.054")) + .unwrap(); + + assert_cmp_display!(a, b, Ordering::Greater); + } }