diff --git a/src/univers/version_range.py b/src/univers/version_range.py index b6ac12b6..74604af7 100644 --- a/src/univers/version_range.py +++ b/src/univers/version_range.py @@ -51,7 +51,7 @@ class VersionRange: constraints = attr.ib(type=tuple, default=attr.Factory(tuple)) def __attrs_post_init__(self, *args, **kwargs): - constraints = tuple(sorted(self.constraints)) + constraints = tuple(sorted(set(self.constraints))) # Notes: setattr is used because this is an immutable frozen instance. # See https://www.attrs.org/en/stable/init.html?#post-init object.__setattr__(self, "constraints", constraints) diff --git a/tests/test_version_range.py b/tests/test_version_range.py index d56b7198..5b37b553 100644 --- a/tests/test_version_range.py +++ b/tests/test_version_range.py @@ -18,6 +18,7 @@ from univers.version_range import RANGE_CLASS_BY_SCHEMES from univers.version_range import NpmVersionRange from univers.version_range import OpensslVersionRange +from univers.version_range import NginxVersionRange from univers.versions import PypiVersion from univers.versions import NugetVersion from univers.versions import RubygemsVersion @@ -278,6 +279,24 @@ def test_nuget_version_range(self): assert version_range == expected assert version_range.to_string() == "vers:nuget/>=1.0.0|<2.0.0" + def test_version_range_constraint_duplication(self): + version_range = VersionRange( + constraints=( + VersionConstraint(comparator=">=", version=SemverVersion(string="1.4.0")), + VersionConstraint(comparator=">=", version=SemverVersion(string="1.4.0")), + VersionConstraint(comparator="=", version=SemverVersion(string="2.5.0")), + VersionConstraint(comparator="=", version=SemverVersion(string="2.5.0")), + ) + ) + + expected = VersionRange( + constraints=( + VersionConstraint(comparator=">=", version=SemverVersion(string="1.4.0")), + VersionConstraint(comparator="=", version=SemverVersion(string="2.5.0")), + ) + ) + assert version_range == expected + VERSION_RANGE_TESTS_BY_SCHEME = { "nginx": ["0.8.40+", "0.7.52-0.8.39", "0.9.10", "1.5.0+, 1.4.1+"],