diff --git a/pkg/registry/client.go b/pkg/registry/client.go index ffecd9571..c2c943d4e 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -643,5 +643,5 @@ func (c *Client) Tags(ref string) ([]string, error) { func tagToVersion(tag string) (*semver.Version, error) { // Change underscore (_) back to plus (+) for Helm // See https://github.com/helm/helm/issues/10166 - return semver.StrictNewVersion(strings.ReplaceAll(tag, "_", "+")) + return semver.NewVersion(strings.ReplaceAll(tag, "_", "+")) } diff --git a/pkg/registry/client_test.go b/pkg/registry/client_test.go index 9b335405c..405dd568e 100644 --- a/pkg/registry/client_test.go +++ b/pkg/registry/client_test.go @@ -384,17 +384,17 @@ func TestTagToVersion(t *testing.T) { "empty": { tag: "", version: nil, - err: "Version string empty", + err: "Invalid Semantic Version", }, "x": { tag: "1", - version: nil, - err: "Invalid Semantic Version", + version: semver.MustParse("1"), + err: "", }, "x.y": { tag: "1.1", - version: nil, - err: "Invalid Semantic Version", + version: semver.MustParse("1.1"), + err: "", }, "x.y.z": { tag: "1.22.333", @@ -411,6 +411,36 @@ func TestTagToVersion(t *testing.T) { version: semver.MustParse("1.22.333+xzy"), err: "", }, + "vX.Y.Z+metadata": { + tag: "v1.22.333_xyz", + version: semver.MustParse("v1.22.333+xyz"), + err: "", + }, + "vX.Y.Z-prerelease": { + tag: "v1.22.333-alpha.0", + version: semver.MustParse("v1.22.333-alpha.0"), + err: "", + }, + "vX.Y.Z": { + tag: "v1.22.333", + version: semver.MustParse("v1.22.333"), + err: "", + }, + "vX.Y": { + tag: "v1.22", + version: semver.MustParse("v1.22"), + err: "", + }, + "vX": { + tag: "v1", + version: semver.MustParse("v1"), + err: "", + }, + "v": { + tag: "v", + version: nil, + err: "Invalid Semantic Version", + }, } for title, tc := range tests { tc := tc