Skip to content

Commit 1dc49ff

Browse files
committed
fix: accept single-point Maven range like [5.0,5.0]
Maven treats identical boundaries as an error only when a side is exclusive; both inclusive means exactly 5.0. Reject only the exclusive forms, matching Apache Maven's own parser. Signed-off-by: Apoorva Verma <vermaapoorva0510@gmail.com>
1 parent 92b1a24 commit 1dc49ff

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/univers/maven.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,19 @@ def __init__(self, spec=None):
7777
_spec = spec[1:-1].strip()
7878
if "," in _spec:
7979
lower_bound, upper_bound = _spec.split(",")
80-
if lower_bound and lower_bound == upper_bound:
81-
raise RestrictionParseError("Range cannot have identical boundaries: %s" % spec)
8280

8381
self.lower_bound = Version(lower_bound) if lower_bound else None
8482
self.upper_bound = Version(upper_bound) if upper_bound else None
8583

86-
if self.lower_bound and self.upper_bound and self.upper_bound < self.lower_bound:
87-
raise RestrictionParseError("Range defies version ordering: %s" % spec)
84+
if self.lower_bound and self.upper_bound:
85+
if self.upper_bound < self.lower_bound:
86+
raise RestrictionParseError("Range defies version ordering: %s" % spec)
87+
# Identical boundaries describe a single hard requirement such as
88+
# [5.0,5.0] and are only valid when both bounds are inclusive.
89+
if self.upper_bound == self.lower_bound and not (
90+
self.lower_bound_inclusive and self.upper_bound_inclusive
91+
):
92+
raise RestrictionParseError("Range cannot have identical boundaries: %s" % spec)
8893
else:
8994
# single version restriction
9095
if not self.lower_bound_inclusive or not self.upper_bound_inclusive:

tests/test_maven_version.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ def test_inclusive_range(self):
9898
assert "1.3.1" not in r
9999
assert "2.0" not in r
100100

101+
def test_identical_inclusive_boundaries(self):
102+
r = Restriction("[5.0,5.0]")
103+
assert str(r.lower_bound) == "5.0"
104+
assert r.lower_bound_inclusive
105+
assert str(r.upper_bound) == "5.0"
106+
assert r.upper_bound_inclusive
107+
108+
assert "4.0" not in r
109+
assert "5.0" in r
110+
assert "5.1" not in r
111+
101112
def test_exclusive_upper_bound(self):
102113
r = Restriction("[1.0,2.0)")
103114
assert str(r.lower_bound) == "1.0"

tests/test_maven_version_range.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ def test_maven_version_range_from_native_for_pinned_version():
3636
)
3737

3838

39+
def test_maven_version_range_from_native_for_single_point_range():
40+
version_range = MavenVersionRange.from_native("[5.0,5.0]")
41+
assert version_range == MavenVersionRange(
42+
constraints=(VersionConstraint(comparator="=", version=MavenVersion(string="5.0")),)
43+
)
44+
45+
3946
def test_maven_version_range_from_native_for_illformed_version():
4047
try:
4148
MavenVersionRange.from_native("(1.0.0]")

0 commit comments

Comments
 (0)