Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changelog/6447.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go/common/version: Trim pre-release suffixes

Updated version.FromString to trim 'rc', 'alpha', and 'beta' suffixes without
hyphens when parsing version strings. Added test cases to ensure correct
parsing of versions with pre-release suffixes.
4 changes: 4 additions & 0 deletions go/common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func FromString(s string) (Version, error) {
s = strings.Split(s, "-")[0]
// Trim potential git commit.
s = strings.Split(s, "+")[0]
// Trim potential pre-release suffixes without hyphen.
s = strings.Split(s, "rc")[0]
s = strings.Split(s, "alpha")[0]
s = strings.Split(s, "beta")[0]
// Take at most four components: major.minor.patch.remainder.
split := strings.SplitN(s, ".", 4)

Expand Down
4 changes: 4 additions & 0 deletions go/common/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func TestFromString(t *testing.T) {
{"1.0", Version{1, 0, 0}},
{"1", Version{1, 0, 0}},
{"1.2.3.4", Version{1, 2, 3}},
{"1.26rc3", Version{1, 26, 0}},
{"1.26-rc3", Version{1, 26, 0}},
{"1.26beta3", Version{1, 26, 0}},
{"1.26-beta3", Version{1, 26, 0}},
} {
version, err := FromString(v.semver)
require.NoError(err)
Expand Down
Loading