internal/genv: fix release notes link for minor versions

Also corrected the code in case of unrecognized version.

According to the docs, nil is returned when the regex does not match.
And in case of a partial or full match, the length of the slice
is always equal to the no. of subexpressions.
For the subexpressions that did not match, the string will be empty.

So the length check was logically wrong. It's just that since the length
of a nil slice is 0, it accidentally turned out to be correct.

Fixes golang/go#26976

Change-Id: Ic9e43d13877d747df20c15949436e355d2fd448d
Reviewed-on: https://go-review.googlesource.com/c/160920
Reviewed-by: Filippo Valsorda <filippo@golang.org>
diff --git a/go1.10.1/main.go b/go1.10.1/main.go
index b5dd3e1..f8d2bed 100644
--- a/go1.10.1/main.go
+++ b/go1.10.1/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.10.1 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.10
+// See the release notes at https://golang.org/doc/devel/release.html#go1.10.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.10.2/main.go b/go1.10.2/main.go
index e4a6573..c592b37 100644
--- a/go1.10.2/main.go
+++ b/go1.10.2/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.10.2 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.10
+// See the release notes at https://golang.org/doc/devel/release.html#go1.10.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.10.3/main.go b/go1.10.3/main.go
index 7d16c0d..d02f2c6 100644
--- a/go1.10.3/main.go
+++ b/go1.10.3/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.10.3 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.10
+// See the release notes at https://golang.org/doc/devel/release.html#go1.10.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.10.4/main.go b/go1.10.4/main.go
index f404f0f..0372b08 100644
--- a/go1.10.4/main.go
+++ b/go1.10.4/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.10.4 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.10
+// See the release notes at https://golang.org/doc/devel/release.html#go1.10.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.10.5/main.go b/go1.10.5/main.go
index 7e22217..3c6cd56 100644
--- a/go1.10.5/main.go
+++ b/go1.10.5/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.10.5 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.10
+// See the release notes at https://golang.org/doc/devel/release.html#go1.10.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.10.6/main.go b/go1.10.6/main.go
index 7b2246a..9cea0fe 100644
--- a/go1.10.6/main.go
+++ b/go1.10.6/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.10.6 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.10
+// See the release notes at https://golang.org/doc/devel/release.html#go1.10.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.10.7/main.go b/go1.10.7/main.go
index c006f65..a526b32 100644
--- a/go1.10.7/main.go
+++ b/go1.10.7/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.10.7 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.10
+// See the release notes at https://golang.org/doc/devel/release.html#go1.10.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.10.8/main.go b/go1.10.8/main.go
index f548e3d..e34f9a5 100644
--- a/go1.10.8/main.go
+++ b/go1.10.8/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.10.8 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.10
+// See the release notes at https://golang.org/doc/devel/release.html#go1.10.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.11.1/main.go b/go1.11.1/main.go
index 7544f19..fef5d4a 100644
--- a/go1.11.1/main.go
+++ b/go1.11.1/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.11.1 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.11
+// See the release notes at https://golang.org/doc/devel/release.html#go1.11.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.11.2/main.go b/go1.11.2/main.go
index 49c2db7..97495a3 100644
--- a/go1.11.2/main.go
+++ b/go1.11.2/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.11.2 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.11
+// See the release notes at https://golang.org/doc/devel/release.html#go1.11.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.11.3/main.go b/go1.11.3/main.go
index d64dc1a..3a6c8bf 100644
--- a/go1.11.3/main.go
+++ b/go1.11.3/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.11.3 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.11
+// See the release notes at https://golang.org/doc/devel/release.html#go1.11.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.11.4/main.go b/go1.11.4/main.go
index e126e4f..9cc46ee 100644
--- a/go1.11.4/main.go
+++ b/go1.11.4/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.11.4 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.11
+// See the release notes at https://golang.org/doc/devel/release.html#go1.11.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.11.5/main.go b/go1.11.5/main.go
index a007c2f..0acc21e 100644
--- a/go1.11.5/main.go
+++ b/go1.11.5/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.11.5 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.11
+// See the release notes at https://golang.org/doc/devel/release.html#go1.11.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.8.1/main.go b/go1.8.1/main.go
index b8d2374..60344f8 100644
--- a/go1.8.1/main.go
+++ b/go1.8.1/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.8.1 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.8
+// See the release notes at https://golang.org/doc/devel/release.html#go1.8.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.8.2/main.go b/go1.8.2/main.go
index 0f55ba0..54d0d80 100644
--- a/go1.8.2/main.go
+++ b/go1.8.2/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.8.2 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.8
+// See the release notes at https://golang.org/doc/devel/release.html#go1.8.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.8.3/main.go b/go1.8.3/main.go
index d371d58..25a93b5 100644
--- a/go1.8.3/main.go
+++ b/go1.8.3/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.8.3 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.8
+// See the release notes at https://golang.org/doc/devel/release.html#go1.8.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.8.4/main.go b/go1.8.4/main.go
index 307e9e5..2aceb01 100644
--- a/go1.8.4/main.go
+++ b/go1.8.4/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.8.4 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.8
+// See the release notes at https://golang.org/doc/devel/release.html#go1.8.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.8.5/main.go b/go1.8.5/main.go
index 9b4ef2d..7298f20 100644
--- a/go1.8.5/main.go
+++ b/go1.8.5/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.8.5 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.8
+// See the release notes at https://golang.org/doc/devel/release.html#go1.8.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.8.6/main.go b/go1.8.6/main.go
index f845876..bff1c05 100644
--- a/go1.8.6/main.go
+++ b/go1.8.6/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.8.6 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.8
+// See the release notes at https://golang.org/doc/devel/release.html#go1.8.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.8.7/main.go b/go1.8.7/main.go
index 5ca105e..1be1d4c 100644
--- a/go1.8.7/main.go
+++ b/go1.8.7/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.8.7 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.8
+// See the release notes at https://golang.org/doc/devel/release.html#go1.8.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.9.1/main.go b/go1.9.1/main.go
index c441f2a..ab294d6 100644
--- a/go1.9.1/main.go
+++ b/go1.9.1/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.9.1 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.9
+// See the release notes at https://golang.org/doc/devel/release.html#go1.9.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.9.2/main.go b/go1.9.2/main.go
index 441f540..1957420 100644
--- a/go1.9.2/main.go
+++ b/go1.9.2/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.9.2 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.9
+// See the release notes at https://golang.org/doc/devel/release.html#go1.9.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.9.3/main.go b/go1.9.3/main.go
index e164f21..1e62158 100644
--- a/go1.9.3/main.go
+++ b/go1.9.3/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.9.3 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.9
+// See the release notes at https://golang.org/doc/devel/release.html#go1.9.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.9.4/main.go b/go1.9.4/main.go
index e47eae8..0620dca 100644
--- a/go1.9.4/main.go
+++ b/go1.9.4/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.9.4 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.9
+// See the release notes at https://golang.org/doc/devel/release.html#go1.9.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.9.5/main.go b/go1.9.5/main.go
index 25fb6c0..82c9fdb 100644
--- a/go1.9.5/main.go
+++ b/go1.9.5/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.9.5 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.9
+// See the release notes at https://golang.org/doc/devel/release.html#go1.9.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.9.6/main.go b/go1.9.6/main.go
index e651dfe..d07b604 100644
--- a/go1.9.6/main.go
+++ b/go1.9.6/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.9.6 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.9
+// See the release notes at https://golang.org/doc/devel/release.html#go1.9.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/go1.9.7/main.go b/go1.9.7/main.go
index f87987b..a843cce 100644
--- a/go1.9.7/main.go
+++ b/go1.9.7/main.go
@@ -12,7 +12,7 @@
 // And then use the go1.9.7 command as if it were your normal go
 // command.
 //
-// See the release notes at https://golang.org/doc/go1.9
+// See the release notes at https://golang.org/doc/devel/release.html#go1.9.minor
 //
 // File bugs at https://golang.org/issues/new
 package main
diff --git a/internal/genv/main.go b/internal/genv/main.go
index ea093a7..01e5c87 100644
--- a/internal/genv/main.go
+++ b/internal/genv/main.go
@@ -69,11 +69,14 @@
 }
 
 func versionNoPatch(ver string) string {
-	rx := regexp.MustCompile(`^(go\d+\.\d+)($|rc|beta|\.)`)
+	rx := regexp.MustCompile(`^(go\d+\.\d+)($|[\.]?\d*)($|rc|beta|\.)`)
 	m := rx.FindStringSubmatch(ver)
-	if len(m) < 2 {
+	if m == nil {
 		failf("unrecognized version %q", ver)
 	}
+	if m[2] != "" {
+		return "devel/release.html#" + m[1] + ".minor"
+	}
 	return m[1]
 }
 
diff --git a/internal/genv/main_test.go b/internal/genv/main_test.go
new file mode 100644
index 0000000..b2ad3cf
--- /dev/null
+++ b/internal/genv/main_test.go
@@ -0,0 +1,20 @@
+package main
+
+import "testing"
+
+func TestVersionNoPatch(t *testing.T) {
+	data := []struct {
+		in  string
+		out string
+	}{
+		{"go1.11.4", "devel/release.html#go1.11.minor"},
+		{"go1.12", "go1.12"},
+		{"go1.12beta1", "go1.12"},
+		{"go1.12rc2", "go1.12"},
+	}
+	for _, item := range data {
+		if out := versionNoPatch(item.in); out != item.out {
+			t.Errorf("versionNoPatch(%q) = %q; want %q", item.in, out, item.out)
+		}
+	}
+}