Skip to content

Commit

Permalink
Handle a version with a dash in the prerelease tag
Browse files Browse the repository at this point in the history
When parsing a constraint, before converting dashes to a range,
check if it is a valid version first. That way a version with multiple
dashes, like v1.0.0-12-abc123 isn't turned into a range of
1.0.0 to 12-abc123.
  • Loading branch information
carolynvs committed Jul 26, 2017
1 parent c2e7f6c commit a93e51b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func TestParseConstraint(t *testing.T) {
includeMin: true,
includeMax: false,
}, false},
{"^1.1.0-12-abc123", rangeConstraint{
min: Version{major: 1, minor: 1, patch: 0, pre: "12-abc123"},
max: newV(2, 0, 0),
includeMin: true,
includeMax: false,
}, false},
}

for _, tc := range tests {
Expand All @@ -70,7 +76,7 @@ func TestParseConstraint(t *testing.T) {
}

if !constraintEq(tc.c, c) {
t.Errorf("Incorrect version found on %s", tc.in)
t.Errorf("%q produced constraint %q, but expected %q", tc.in, c, tc.c)
}
}
}
Expand Down Expand Up @@ -331,6 +337,12 @@ func TestNewConstraintIC(t *testing.T) {
max: newV(2, 0, 0),
includeMin: true,
}, false},
{"v1.1.0-12-abc123", rangeConstraint{
min: Version{major: 1, minor: 1, patch: 0, pre: "12-abc123"},
max: newV(2, 0, 0),
includeMin: true,
includeMax: false,
}, false},
}

for _, tc := range tests {
Expand Down Expand Up @@ -548,6 +560,7 @@ func TestRewriteRange(t *testing.T) {
{"2-3", ">= 2, <= 3"},
{"2-3, 2-3", ">= 2, <= 3,>= 2, <= 3"},
{"2-3, 4.0.0-5.1", ">= 2, <= 3,>= 4.0.0, <= 5.1"},
{"v2-3, 2-3", "v2-3,>= 2, <= 3"},
}

for _, tc := range tests {
Expand Down
3 changes: 3 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func rewriteRange(i string) string {
}
o := i
for _, v := range m {
if strings.HasPrefix(v[0], "v") && versionRegex.MatchString(v[0]) {
continue
}
t := fmt.Sprintf(">= %s, <= %s", v[1], v[11])
o = strings.Replace(o, v[0], t, 1)
}
Expand Down

0 comments on commit a93e51b

Please sign in to comment.