Skip to content

Commit

Permalink
fix: non-alphanumeric characters as separators
Browse files Browse the repository at this point in the history
This switches the logic so we treat all non-alphanumeric characters as
separators equivalent to `.` in version strings.  This should make the
code more robust to unusual version strings.

* Fixes intel#3558 (in that we will be able to handle `~`)

Signed-off-by: Terri Oda <terri@toybox.ca>
  • Loading branch information
terriko committed Dec 6, 2023
1 parent a296b42 commit 79cb075
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cve_bin_tool/version_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ def parse_version(version_string: str):
versionString = version_string.strip()
versionArray = []

# convert - and _ to be treated like . below
# convert all non alpha-numeric characters to be treated like . below
# we could switch to a re split but it seems to leave blanks so this is less hassle
versionString = versionString.replace("-", ".")
versionString = versionString.replace("_", ".")
versionString = versionString.replace("+", ".")
# Note: there may be other non-alphanumeric characters we want to add here in the
# future, but we'd like to look at those cases before adding them in case the version
# logic is very different.
versionString = re.sub("[^0-9a-zA-Z]+", ".", versionString)

# Note: This expression may need improvement if we need to handle unicode

# Attempt a split
split_version = versionString.split(".")
Expand Down

0 comments on commit 79cb075

Please sign in to comment.