]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix GOTOOLCHAIN parsing for +auto
authorRuss Cox <rsc@golang.org>
Tue, 11 Jul 2023 19:15:51 +0000 (15:15 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 12 Jul 2023 18:25:28 +0000 (18:25 +0000)
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 #61068.

Change-Id: I505ceb227457d6a51bd5e47f009b2fb1010c0d1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/508820
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/gover/gover.go
src/cmd/go/internal/gover/gover_test.go
src/cmd/go/internal/gover/toolchain.go
src/cmd/go/internal/toolchain/select.go
src/cmd/go/testdata/script/gotoolchain_local.txt

index ce2242d522659cbc7d5fef72a18c820bdab8676a..b2a8261feb3ae2d85918da0425922c28c71a493c 100644 (file)
@@ -179,6 +179,9 @@ func parse(x string) version {
        // Parse prerelease.
        i := 0
        for i < len(x) && (x[i] < '0' || '9' < x[i]) {
+               if x[i] < 'a' || 'z' < x[i] {
+                       return version{}
+               }
                i++
        }
        if i == 0 {
index 97b3b761c885e133d00a32b157b3c67bcb2bc70d..3a0bf10fc563440f2b4b241b7e2f59865afe1a10 100644 (file)
@@ -95,6 +95,25 @@ var prevTests = []testCase1[string, string]{
        {"1.40000000000000000", "1.39999999999999999"},
 }
 
+func TestIsValid(t *testing.T) { test1(t, isValidTests, "IsValid", IsValid) }
+
+var isValidTests = []testCase1[string, bool]{
+       {"1.2rc3", true},
+       {"1.2.3", true},
+       {"1.999testmod", true},
+       {"1.600+auto", false},
+       {"1.22", true},
+       {"1.21.0", true},
+       {"1.21rc2", true},
+       {"1.21", true},
+       {"1.20.0", true},
+       {"1.20", true},
+       {"1.19", true},
+       {"1.3", true},
+       {"1.2", true},
+       {"1", true},
+}
+
 type testCase1[In, Out any] struct {
        in  In
        out Out
index efa2de46a51acd313d2f785e82d773809b6f3f65..b520277618549a4b0a74f92277f42edc816489f8 100644 (file)
@@ -15,7 +15,7 @@ import (
 // FromToolchain returns the Go version for the named toolchain,
 // derived from the name itself (not by running the toolchain).
 // A toolchain is named "goVERSION".
-// A suffix after the VERSION introduced by a +, -, space, or tab is removed.
+// A suffix after the VERSION introduced by a -, space, or tab is removed.
 // Examples:
 //
 //     FromToolchain("go1.2.3") == "1.2.3"
index 8b1a0b94be4d83e4d2a3cb103ab02f566afd2746..a44f393bc0f0dc657941a7ee8676e028438e846f 100644 (file)
@@ -131,7 +131,7 @@ func Select() {
        } else {
                min, suffix, plus := strings.Cut(gotoolchain, "+") // go1.2.3+auto
                if min != "local" {
-                       v := gover.FromToolchain(gotoolchain)
+                       v := gover.FromToolchain(min)
                        if v == "" {
                                if plus {
                                        base.Fatalf("invalid GOTOOLCHAIN %q: invalid minimum toolchain %q", gotoolchain, min)
index 0e08207f451714cf6c0b4dd49573cb0899193d77..93f557008a64635064dbd65dffee5d03edbbdc12 100644 (file)
@@ -34,9 +34,9 @@ env GOTOOLCHAIN=go1.600+auto
 go version
 stdout go1.600
 
-env GOTOOLCHAIN=go1.400+auto
+env GOTOOLCHAIN=go1.400.0+auto
 go version
-stdout go1.400
+stdout go1.400.0
 
 # GOTOOLCHAIN=version+path sets a minimum too.
 env GOTOOLCHAIN=go1.600+path