Skip to content

Commit 29a06e2

Browse files
versions: Requested versions eligible only if they were already present
The versions.MeetingConstraints method tried to permit selection of any prereleases explicitly requested by an exact version constraint, but it didn't also check that those prereleases were included in the original set. That worked okay for positive exact version constraints, like "1.0.0-beta.1", but was incorrect for negative ones like "! 1.0.0-beta.1" which still get counted as "requested" in certain cases but that should not cause them to then be included in the overall result set. Now we'll filter the list of requested versions first by membership of the "exact" set, so that the requested status of a version can only return versions that would've been eligible for inclusion in the original unfiltered set.
1 parent 0273b66 commit 29a06e2

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

versions/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func MeetingConstraints(spec constraints.Spec) Set {
4949
exact := MeetingConstraintsExact(spec)
5050
reqd := exact.AllRequested().List()
5151
set := Intersection(Released, exact)
52-
reqd = reqd.Filter(Prerelease)
52+
reqd = reqd.Filter(Prerelease).Filter(exact)
5353
if len(reqd) != 0 {
5454
set = Union(Selection(reqd...), set)
5555
}

versions/parse_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ func TestMeetingConstraintsRuby(t *testing.T) {
382382
All.Subtract(Only(MustParseVersion(`1.0.0`))),
383383
),
384384
},
385+
{
386+
`1.0.0-beta1, != 1.0.0-beta1`, // degenerate empty set with prerelease versions
387+
Intersection(
388+
Released,
389+
Only(MustParseVersion(`1.0.0-beta1`)),
390+
All.Subtract(Only(MustParseVersion(`1.0.0-beta1`))),
391+
),
392+
},
385393
}
386394

387395
for _, test := range tests {

versions/set_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ func TestSetHas(t *testing.T) {
228228
MustParseVersion("2.0.0-beta1"),
229229
true,
230230
},
231+
{
232+
MustMakeSet(MeetingConstraintsStringRuby("!= 2.0.0-beta1, 2.0.0-beta1")),
233+
MustParseVersion("2.0.0-beta1"),
234+
false, // the constraint is contradictory, so includes nothing
235+
},
231236
{
232237
MustMakeSet(MeetingConstraintsStringRuby(">= 1.0.0")),
233238
MustParseVersion("1.0.1"),

0 commit comments

Comments
 (0)