From 5cb5aac57e10c0a5005501c153e1f7df387f62df Mon Sep 17 00:00:00 2001 From: BenWeber42 Date: Wed, 28 Apr 2021 16:28:09 +0200 Subject: 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 --- lib/spack/spack/test/versions.py | 3 +++ lib/spack/spack/version.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/test/versions.py b/lib/spack/spack/test/versions.py index ce222c5ea2..a33f7e08f7 100644 --- a/lib/spack/spack/test/versions.py +++ b/lib/spack/spack/test/versions.py @@ -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', ':1.6.5') + check_intersection('11.2', '11', '11.2') + check_intersection('11.2', '11.2', '11') + def test_union_with_containment(): check_union(':1.6', '1.6.5', ':1.6') diff --git a/lib/spack/spack/version.py b/lib/spack/spack/version.py index 321a03efc7..82c0afd53e 100644 --- a/lib/spack/spack/version.py +++ b/lib/spack/spack/version.py @@ -372,8 +372,10 @@ class Version(object): @coerced def intersection(self, other): - if self == other: + if self in other: # also covers `self == other` return self + elif other in self: + return other else: return VersionList() -- cgit v1.2.3-60-g2f50