From 40ca8c923581f6d2b92646d2c7ceca67c4e530f5 Mon Sep 17 00:00:00 2001 From: Terri Oda Date: Thu, 9 Feb 2023 18:02:07 -0800 Subject: [PATCH] refactor: remove unecessary ifs --- cve_bin_tool/cve_scanner.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cve_bin_tool/cve_scanner.py b/cve_bin_tool/cve_scanner.py index 6feebb28db..b09fab30e9 100644 --- a/cve_bin_tool/cve_scanner.py +++ b/cve_bin_tool/cve_scanner.py @@ -338,16 +338,13 @@ def parse_version(self, version_string: str) -> Tuple[Version]: version_string = re.sub("_", ".", version_string) # handle leading product name like curl-7.57.0 by truncating - if re.match("[a-zA-Z]*-", version_string): - version_string = re.sub("[a-zA-Z]*-", "", version_string) + version_string = re.sub("^[a-zA-Z]*-", "", version_string) # Or just convert the - to a . for cases like `5-1.6` - if "-" in version_string: - version_string = re.sub("-", ".", version_string) + version_string = re.sub("-", ".", version_string) # handle trailing letters a la '1.6.3.kdc' by truncating - if re.match(r"\.[a-zA-Z]*$", version_string): - version_string = re.sub(r"\.[a-zA-Z]*$", "", version_string) + version_string = re.sub(r"\.[a-zA-Z]*$", "", version_string) # Otherwise just try to parse it with packaging's parse parsed_version = packaging_parse(version_string)