Skip to content

Commit

Permalink
Fix 1387 (aboutcode-org#1389)
Browse files Browse the repository at this point in the history
* Fix issue 1387

Reference: aboutcode-org#1387

Signed-off-by: Tushar Goel <[email protected]>

* Add tests

Signed-off-by: Tushar Goel <[email protected]>

---------

Signed-off-by: Tushar Goel <[email protected]>
  • Loading branch information
TG1999 committed Jul 19, 2024
1 parent 0c22b0c commit f1701e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion vulnerabilities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from rest_framework.authtoken.models import Token
from univers import versions
from univers.version_range import RANGE_CLASS_BY_SCHEMES
from univers.version_range import AlpineLinuxVersionRange
from univers.versions import Version

from vulnerabilities import utils
from vulnerabilities.severity_systems import SCORING_SYSTEMS
Expand Down Expand Up @@ -645,7 +647,11 @@ def sort_by_version(self, packages):

@property
def version_class(self):
return RANGE_CLASS_BY_SCHEMES[self.type].version_class
RANGE_CLASS_BY_SCHEMES["alpine"] = AlpineLinuxVersionRange
range_class = RANGE_CLASS_BY_SCHEMES.get(self.type)
if not range_class:
return Version
return range_class.version_class

@property
def current_version(self):
Expand Down
4 changes: 2 additions & 2 deletions vulnerabilities/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ def test_univers_version_class(self):
pypi_package_version = RANGE_CLASS_BY_SCHEMES[pypi_package.type].version_class
assert pypi_package_version == versions.PypiVersion

RANGE_CLASS_BY_SCHEMES["alpine"] = AlpineLinuxVersionRange
alpine_version = RANGE_CLASS_BY_SCHEMES["alpine"].version_class
alpine_package = models.Package.objects.create(type="alpine", name="lxml", version="0.9")
alpine_version = RANGE_CLASS_BY_SCHEMES[alpine_package.type].version_class
assert alpine_version == versions.AlpineLinuxVersion

def test_sort_by_version(self):
Expand Down

0 comments on commit f1701e0

Please sign in to comment.