diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-11-14 23:15:01 +0000 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-11-14 23:15:01 +0000 |
| commit | 5a793bebe888b74e21c6f68dfa05c3ddddf63703 (patch) | |
| tree | 97ba8f4619551d2e45616ef1cbca5ee7dd98a529 /src | |
| parent | 07d1823f0fc0a21ebc7858a154bd877040ccb470 (diff) | |
| download | gentoo-utils-5a793bebe888b74e21c6f68dfa05c3ddddf63703.tar.gz | |
check if a OR b has leading zeros, and if so, strip and do ascii cmp
Diffstat (limited to 'src')
| -rw-r--r-- | src/atom/mod.rs | 16 |
1 files changed, 15 insertions, 1 deletions
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); + } } |
