Fix intersection if a version is a prefix of another (#22941)

* Added test for version intersections when one is prefix of another

* Fix version intersection for prefixes
This commit is contained in:
BenWeber42 2021-04-28 16:28:09 +02:00 committed by GitHub
parent 6ab859fb45
commit 5cb5aac57e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -373,6 +373,9 @@ def test_intersect_with_containment():
check_intersection('1.6:1.6.5', ':1.6.5', '1.6') check_intersection('1.6:1.6.5', ':1.6.5', '1.6')
check_intersection('1.6:1.6.5', '1.6', ':1.6.5') check_intersection('1.6:1.6.5', '1.6', ':1.6.5')
check_intersection('11.2', '11', '11.2')
check_intersection('11.2', '11.2', '11')
def test_union_with_containment(): def test_union_with_containment():
check_union(':1.6', '1.6.5', ':1.6') check_union(':1.6', '1.6.5', ':1.6')

View File

@ -372,8 +372,10 @@ def union(self, other):
@coerced @coerced
def intersection(self, other): def intersection(self, other):
if self == other: if self in other: # also covers `self == other`
return self return self
elif other in self:
return other
else: else:
return VersionList() return VersionList()