]> Cypherpunks repositories - gostls13.git/commitdiff
gover: support Semantic Versioning major versions beyond 1
authorlotusirous <ngtrongkha92@gmail.com>
Mon, 13 Nov 2023 15:03:09 +0000 (22:03 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 6 Dec 2023 21:39:46 +0000 (21:39 +0000)
For #64033

Change-Id: Iab132f86c66aa6115a349d8032e9766a14dad02e
Reviewed-on: https://go-review.googlesource.com/c/go/+/541915
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>

src/go/version/version.go
src/go/version/version_test.go

index 20c9cbc4770c408a40290cac892a4f9a99b7a8ea..466c8091ea6c0fcc5b762d37817412ed163b3279 100644 (file)
@@ -7,7 +7,10 @@
 // [Go versions]: https://go.dev/doc/toolchain#version
 package version // import "go/version"
 
-import "internal/gover"
+import (
+       "internal/gover"
+       "strings"
+)
 
 // stripGo converts from a "go1.21" version to a "1.21" version.
 // If v does not start with "go", stripGo returns the empty string (a known invalid version).
@@ -33,7 +36,11 @@ func Lang(x string) string {
        if v == "" {
                return ""
        }
-       return x[:2+len(v)] // "go"+v without allocation
+       if strings.HasPrefix(x[2:], v) {
+               return x[:2+len(v)] // "go"+v without allocation
+       } else {
+               return "go" + v
+       }
 }
 
 // Compare returns -1, 0, or +1 depending on whether
index 62aabad3a1937a1afa702aa8a54ed04aac60770c..7c12e7ffd96f8d2c9017a7669d88181efc4f32ec 100644 (file)
@@ -48,6 +48,7 @@ var langTests = []testCase1[string, string]{
        {"go1.2.3", "go1.2"},
        {"go1.2", "go1.2"},
        {"go1", "go1"},
+       {"go222", "go222.0"},
        {"go1.999testmod", "go1.999"},
 }