Skip to content

Commit b995362

Browse files
rscbradfitz
authored andcommitted
cmd/go: fix GOTOOLCHAIN parsing for +auto
The call from toolchain.Select to gover.FromToolchain was passing the wrong argument but this was masked by gover.IsValid being a little bit too lax. Fix and test IsValid, which then breaks the existing gotoolchain_local test, and then fix toolchain.Select to fix the test. Fixes golang#61068. Change-Id: I505ceb227457d6a51bd5e47f009b2fb1010c0d1f Reviewed-on: https://go-review.googlesource.com/c/go/+/508820 Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 83ffbf3 commit b995362

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

src/cmd/go/internal/gover/gover.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ func parse(x string) version {
179179
// Parse prerelease.
180180
i := 0
181181
for i < len(x) && (x[i] < '0' || '9' < x[i]) {
182+
if x[i] < 'a' || 'z' < x[i] {
183+
return version{}
184+
}
182185
i++
183186
}
184187
if i == 0 {

src/cmd/go/internal/gover/gover_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ var prevTests = []testCase1[string, string]{
9595
{"1.40000000000000000", "1.39999999999999999"},
9696
}
9797

98+
func TestIsValid(t *testing.T) { test1(t, isValidTests, "IsValid", IsValid) }
99+
100+
var isValidTests = []testCase1[string, bool]{
101+
{"1.2rc3", true},
102+
{"1.2.3", true},
103+
{"1.999testmod", true},
104+
{"1.600+auto", false},
105+
{"1.22", true},
106+
{"1.21.0", true},
107+
{"1.21rc2", true},
108+
{"1.21", true},
109+
{"1.20.0", true},
110+
{"1.20", true},
111+
{"1.19", true},
112+
{"1.3", true},
113+
{"1.2", true},
114+
{"1", true},
115+
}
116+
98117
type testCase1[In, Out any] struct {
99118
in In
100119
out Out

src/cmd/go/internal/gover/toolchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// FromToolchain returns the Go version for the named toolchain,
1616
// derived from the name itself (not by running the toolchain).
1717
// A toolchain is named "goVERSION".
18-
// A suffix after the VERSION introduced by a +, -, space, or tab is removed.
18+
// A suffix after the VERSION introduced by a -, space, or tab is removed.
1919
// Examples:
2020
//
2121
// FromToolchain("go1.2.3") == "1.2.3"

src/cmd/go/internal/toolchain/select.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func Select() {
131131
} else {
132132
min, suffix, plus := strings.Cut(gotoolchain, "+") // go1.2.3+auto
133133
if min != "local" {
134-
v := gover.FromToolchain(gotoolchain)
134+
v := gover.FromToolchain(min)
135135
if v == "" {
136136
if plus {
137137
base.Fatalf("invalid GOTOOLCHAIN %q: invalid minimum toolchain %q", gotoolchain, min)

src/cmd/go/testdata/script/gotoolchain_local.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ env GOTOOLCHAIN=go1.600+auto
3434
go version
3535
stdout go1.600
3636

37-
env GOTOOLCHAIN=go1.400+auto
37+
env GOTOOLCHAIN=go1.400.0+auto
3838
go version
39-
stdout go1.400
39+
stdout go1.400.0
4040

4141
# GOTOOLCHAIN=version+path sets a minimum too.
4242
env GOTOOLCHAIN=go1.600+path

0 commit comments

Comments
 (0)