From 33fa0cba16b6230fd638909be0dba0d422d4b898 Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Wed, 30 Jan 2019 13:52:09 -0500 Subject: [PATCH] Added a check for a valid version before all version uses --- src/release/release.go | 12 ++++++++++++ src/release/release_test.go | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/release/release.go b/src/release/release.go index c0d85a80..1cc2aa54 100644 --- a/src/release/release.go +++ b/src/release/release.go @@ -123,6 +123,10 @@ func installLatest(latestURL string, install func(platform) error) error { } func installVersion(ver, releasesURL string, install func(platform) error) error { + if _, err := version.NewVersion(ver); err != nil { + return err + } + releases, err := fetchReleases(releasesURL) if err != nil { return err @@ -163,6 +167,10 @@ func applyUpdate(platformRelease platform, targetPath string) error { } func update(ver, releasesURL, distDir string, force bool, u uploader) error { + if _, err := version.NewVersion(ver); err != nil { + return err + } + if !force { requestedVersion, _ := version.NewVersion(ver) if !requestedVersion.Equal(ThemeKitVersion) { @@ -193,6 +201,10 @@ func update(ver, releasesURL, distDir string, force bool, u uploader) error { } func remove(ver, releaseURL string, u uploader) error { + if _, err := version.NewVersion(ver); err != nil { + return err + } + releases, err := fetchReleases(releaseURL) if err != nil { return err diff --git a/src/release/release_test.go b/src/release/release_test.go index 06d3a671..e81b5153 100644 --- a/src/release/release_test.go +++ b/src/release/release_test.go @@ -115,6 +115,7 @@ func TestInstallVersion(t *testing.T) { }{ {in: "0.4.7"}, {in: "0.0.0", err: "version 0.0.0 not found"}, + {in: "v.0.8.2", err: "Malformed version: v.0.8.2"}, } for _, testcase := range testcases { @@ -171,6 +172,7 @@ func TestUpdate(t *testing.T) { {ver: ThemeKitVersion.String(), dir: filepath.Join("_testdata", "dist"), req: true, err: "version has already been deployed"}, {ver: ThemeKitVersion.String(), dir: filepath.Join("_testdata", "otherdist"), err: " "}, {ver: ThemeKitVersion.String(), dir: filepath.Join("_testdata", "dist")}, + {ver: "v.0.8.2", err: "Malformed version: v.0.8.2"}, } for _, testcase := range testcases { @@ -209,6 +211,7 @@ func TestRemove(t *testing.T) { }{ {ver: "12.34.56", err: "version has not be deployed"}, {ver: "0.4.7"}, + {ver: "v.0.8.2", err: "Malformed version: v.0.8.2"}, } for _, testcase := range testcases {