Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorElliott Sales de Andrade <quantum.analyst@gmail.com>2020-02-19 10:46:21 +0300
committerGitHub <noreply@github.com>2020-02-19 10:46:21 +0300
commitc7975b48b6532823868a6aa8c93eb76caa46c570 (patch)
treece1eb059da1409aceeed804afb82b3fec41f3c91 /common
parentb2dcd53e3c0240c4afd21d1818fd180c2d1b9d34 (diff)
Fix goMinorVersion on non-final Go releases
This should work for alpha/beta/rc releases.
Diffstat (limited to 'common')
-rw-r--r--common/hugo/version.go16
-rw-r--r--common/hugo/version_test.go1
2 files changed, 13 insertions, 4 deletions
diff --git a/common/hugo/version.go b/common/hugo/version.go
index 848393f97..038537fc0 100644
--- a/common/hugo/version.go
+++ b/common/hugo/version.go
@@ -15,7 +15,7 @@ package hugo
import (
"fmt"
- "strconv"
+ "io"
"runtime"
"strings"
@@ -245,7 +245,15 @@ func goMinorVersion(version string) int {
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
}
diff --git a/common/hugo/version_test.go b/common/hugo/version_test.go
index e0cd0e6e8..9e0ebb295 100644
--- a/common/hugo/version_test.go
+++ b/common/hugo/version_test.go
@@ -84,5 +84,6 @@ func TestParseHugoVersion(t *testing.T) {
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)
}