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 1.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 af60833
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 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
3 changes: 3 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

func rewriteRange(i string) string {
if versionRegex.MatchString(i) {
return i
}
m := constraintRangeRegex.FindAllStringSubmatch(i, -1)
if m == nil {
return i
Expand Down

0 comments on commit af60833

Please sign in to comment.