From 58e74c33134cfa54a706d55e04bf1f5dda830705 Mon Sep 17 00:00:00 2001 From: Dustin Born Date: Tue, 13 Feb 2024 13:04:50 +0100 Subject: [PATCH] Fix version comparison bugs Example comparisons that work correctly now: * 1.1k < 1.1k-12 * 1.1e < 1.1ek --- cpe_version.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpe_version.py b/cpe_version.py index 06aa91a..29c4ae8 100644 --- a/cpe_version.py +++ b/cpe_version.py @@ -108,7 +108,9 @@ def __lt__(self, other): for i in range(iter_max): if ord(part[i].lower()) > ord(other_part[i].lower()): return False - if i == iter_max - 1 and ord(part[i].lower()) == ord(other_part[i].lower()): + if (i == iter_max - 1 and len(parts) == len(other_parts) and + len(part) == len(other_part) and + ord(part[i].lower()) == ord(other_part[i].lower())): return False else: for i, char in enumerate(part): @@ -132,7 +134,7 @@ def __lt__(self, other): return True # if version part in front is smaller, the entire version is already smaller - if len(other_parts) > len(other_parts): + if len(parts) > len(other_parts): return False return True