From 2a5d87b197a779cb9e0ec71657de2b4bd808f286 Mon Sep 17 00:00:00 2001 From: Benjamin Peinhardt <61021968+bcpeinhardt@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:30:25 -0500 Subject: [PATCH] fix: fix bug with trailing version info not being properly stripped (#14963) Fixes a bug where excess version info was not being stripped properly from documentation links. --- codersdk/deployment.go | 6 ++++- codersdk/deployment_internal_test.go | 36 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 codersdk/deployment_internal_test.go diff --git a/codersdk/deployment.go b/codersdk/deployment.go index ed4d66001d8d6..be52bfa6df4eb 100644 --- a/codersdk/deployment.go +++ b/codersdk/deployment.go @@ -804,8 +804,12 @@ func DefaultSupportLinks(docsURL string) []LinkConfig { } } +func removeTrailingVersionInfo(v string) string { + return strings.Split(strings.Split(v, "-")[0], "+")[0] +} + func DefaultDocsURL() string { - version := strings.Split(buildinfo.Version(), "-")[0] + version := removeTrailingVersionInfo(buildinfo.Version()) if version == "v0.0.0" { return "https://coder.com/docs" } diff --git a/codersdk/deployment_internal_test.go b/codersdk/deployment_internal_test.go new file mode 100644 index 0000000000000..09ee7f2a2cc71 --- /dev/null +++ b/codersdk/deployment_internal_test.go @@ -0,0 +1,36 @@ +package codersdk + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestRemoveTrailingVersionInfo(t *testing.T) { + t.Parallel() + + testCases := []struct { + Version string + ExpectedAfterStrippingInfo string + }{ + { + Version: "v2.16.0+683a720", + ExpectedAfterStrippingInfo: "v2.16.0", + }, + { + Version: "v2.16.0-devel+683a720", + ExpectedAfterStrippingInfo: "v2.16.0", + }, + { + Version: "v2.16.0+683a720-devel", + ExpectedAfterStrippingInfo: "v2.16.0", + }, + } + + for _, tc := range testCases { + tc := tc + + stripped := removeTrailingVersionInfo(tc.Version) + require.Equal(t, tc.ExpectedAfterStrippingInfo, stripped) + } +}
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: