check if a OR b has leading zeros, and if so, strip and do ascii cmp

This commit is contained in:
John Turner
2025-11-14 23:15:01 +00:00
parent 07d1823f0f
commit 5a793bebe8

View File

@@ -293,7 +293,9 @@ impl Ord for VersionNumbers {
loop { loop {
match (a.next(), b.next()) { 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 a = a.get().trim_end_matches("0");
let b = b.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); 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);
}
} }