From af60833ec64bcef335abd90c326ea922d59b76a9 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Wed, 26 Jul 2017 16:53:14 -0500 Subject: [PATCH] Handle a version with a dash in the prerelease tag 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. --- constraints_test.go | 8 +++++++- parse.go | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/constraints_test.go b/constraints_test.go index a45714d..9ee287f 100644 --- a/constraints_test.go +++ b/constraints_test.go @@ -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 { @@ -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) } } } diff --git a/parse.go b/parse.go index d6afa6c..f40537d 100644 --- a/parse.go +++ b/parse.go @@ -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