ref: c7975b48b6532823868a6aa8c93eb76caa46c570
parent: b2dcd53e3c0240c4afd21d1818fd180c2d1b9d34
author: Elliott Sales de Andrade <quantum.analyst@gmail.com>
date: Tue Feb 18 21:46:21 EST 2020
Fix goMinorVersion on non-final Go releases This should work for alpha/beta/rc releases.
--- a/common/hugo/version.go
+++ b/common/hugo/version.go
@@ -15,7 +15,7 @@
import (
"fmt"
- "strconv"
+ "io"
"runtime"
"strings"
@@ -245,7 +245,15 @@
if strings.HasPrefix(version, "devel") {
return 9999 // magic
}
- i, _ := strconv.Atoi(strings.Split(version, ".")[1])
- return i
-
+ var major, minor int
+ var trailing string
+ n, err := fmt.Sscanf(version, "go%d.%d%s", &major, &minor, &trailing)
+ if n == 2 && err == io.EOF {
+ // Means there were no trailing characters (i.e., not an alpha/beta)
+ err = nil
+ }
+ if err != nil {
+ return 0
+ }
+ return minor
}
--- a/common/hugo/version_test.go
+++ b/common/hugo/version_test.go
@@ -84,5 +84,6 @@
func TestGoMinorVersion(t *testing.T) {
c := qt.New(t)
c.Assert(goMinorVersion("go1.12.5"), qt.Equals, 12)
+ c.Assert(goMinorVersion("go1.14rc1"), qt.Equals, 14)
c.Assert(GoMinorVersion() >= 11, qt.Equals, true)
}