summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenWeber42 <dev.ben.weber@gmail.com>2021-04-28 16:28:09 +0200
committerGitHub <noreply@github.com>2021-04-28 08:28:09 -0600
commit5cb5aac57e10c0a5005501c153e1f7df387f62df (patch)
treeec047ac8759340ab38b7cb813eaef02be29f7969
parent6ab859fb45bb3e4a7b2f3b712d24734ffd3aa7eb (diff)
downloadspack-5cb5aac57e10c0a5005501c153e1f7df387f62df.tar.gz
spack-5cb5aac57e10c0a5005501c153e1f7df387f62df.tar.bz2
spack-5cb5aac57e10c0a5005501c153e1f7df387f62df.tar.xz
spack-5cb5aac57e10c0a5005501c153e1f7df387f62df.zip
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
-rw-r--r--lib/spack/spack/test/versions.py3
-rw-r--r--lib/spack/spack/version.py4
2 files changed, 6 insertions, 1 deletions
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()