Skip to content

Commit 6d25636

Browse files
committed
Don't treat x in pre-release and build metadata identifiers as a wildcard
Signed-off-by: Max Brauer <[email protected]>
1 parent 5409682 commit 6d25636

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

v4/range.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func expandWildcardVersion(parts [][]string) ([][]string, error) {
327327
for _, p := range parts {
328328
var newParts []string
329329
for _, ap := range p {
330-
if strings.Contains(ap, "x") {
330+
if containsWildcard(ap) {
331331
opStr, vStr, err := splitComparatorVersion(ap)
332332
if err != nil {
333333
return nil, err
@@ -381,6 +381,12 @@ func expandWildcardVersion(parts [][]string) ([][]string, error) {
381381
return expandedParts, nil
382382
}
383383

384+
// containsWildcard returns true iff there's a wildcard in any of the major, minor or patch components
385+
func containsWildcard(v string) bool {
386+
withoutPrereleaseBuildMeta := strings.Split(strings.Split(v, "+")[0], "-")[0]
387+
return strings.Contains(withoutPrereleaseBuildMeta, "x")
388+
}
389+
384390
func parseComparator(s string) comparator {
385391
switch s {
386392
case "==":

v4/range_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ func TestGetWildcardType(t *testing.T) {
202202
{"x", majorWildcard},
203203
{"1.x", minorWildcard},
204204
{"1.2.x", patchWildcard},
205+
{"1.2.3-experimental", noneWildcard},
205206
{"fo.o.b.ar", noneWildcard},
206207
}
207208

@@ -387,6 +388,16 @@ func TestParseRange(t *testing.T) {
387388
{"1.2.3", true},
388389
{"1.2.4", false},
389390
}},
391+
{"1.2.3-experimental.2", []tv{
392+
{"1.2.3-experimental.1", false},
393+
{"1.2.3-experimental.2", true},
394+
{"1.2.3-experimental.3", false},
395+
}},
396+
{"1.2.3+experimental.2", []tv{
397+
{"1.2.3+experimental.1", false},
398+
{"1.2.3+experimental.2", true},
399+
{"1.2.3+experimental.3", false},
400+
}},
390401
{"=1.2.3", []tv{
391402
{"1.2.2", false},
392403
{"1.2.3", true},

0 commit comments

Comments
 (0)