diff --git a/go/extractor/util/semver.go b/go/extractor/util/semver.go index 563fbc5a9e342..68ccb9072d052 100644 --- a/go/extractor/util/semver.go +++ b/go/extractor/util/semver.go @@ -91,15 +91,12 @@ func NewSemVer(version string) SemVer { version = "v" + version } - // Convert the remaining version string to a canonical semantic version, - // and check that this was successful. - canonical := semver.Canonical(version) - - if canonical == "" { + // Check that the remaining version string is valid. + if !semver.IsValid(version) { log.Fatalf("%s is not a valid version string\n", version) } - return semVer(canonical) + return semVer(version) } func (ver semVer) Compare(other SemVer) int { diff --git a/go/extractor/util/semver_test.go b/go/extractor/util/semver_test.go index 30b755b14452b..704332ba8a791 100644 --- a/go/extractor/util/semver_test.go +++ b/go/extractor/util/semver_test.go @@ -1,6 +1,10 @@ package util -import "testing" +import ( + "testing" + + "golang.org/x/mod/semver" +) func TestNewSemVer(t *testing.T) { type TestPair struct { @@ -15,10 +19,10 @@ func TestNewSemVer(t *testing.T) { } testData := []TestPair{ - {"0", "v0.0.0"}, - {"1.0", "v1.0.0"}, + {"0", "v0"}, + {"1.0", "v1.0"}, {"1.0.2", "v1.0.2"}, - {"1.20", "v1.20.0"}, + {"1.20", "v1.20"}, {"1.22.3", "v1.22.3"}, } @@ -31,13 +35,13 @@ func TestNewSemVer(t *testing.T) { for _, pair := range testData { for _, prefix := range prefixes { for _, suffix := range suffixes { - // c + // combine the input string with the current prefix and suffix input := prefix + pair.Input + suffix result := NewSemVer(input) expected := pair.Expected if suffix != "" { - expected += "-rc1" + expected = semver.Canonical(pair.Expected) + "-rc1" } if result.String() != expected {