internal: CandidateModulePaths checks for valid module paths

Previously, it was checking for valid _import_ paths, but some valid
import paths are not valid module paths.

Change-Id: Ib8d970169462744b7700ec623dbfe1319756a7d1
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/350109
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/frontend/fetch.go b/internal/frontend/fetch.go
index 0599b48..92508fd 100644
--- a/internal/frontend/fetch.go
+++ b/internal/frontend/fetch.go
@@ -86,7 +86,7 @@
 )
 
 // serveFetch checks if a requested path and version exists in the database.
-// If not, it will enqueuing potential module versions that could contain
+// If not, it will enqueue potential module versions that could contain
 // the requested path and version to a task queue, to be fetched by the worker.
 // Meanwhile, the request will poll the database until a row is found, or a
 // timeout occurs. A status and responseText will be returned based on the
@@ -94,7 +94,7 @@
 func (s *Server) serveFetch(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error) {
 	defer derrors.Wrap(&err, "serveFetch(%q)", r.URL.Path)
 	if _, ok := ds.(*postgres.DB); !ok {
-		// There's no reason for the proxydatasource to need this codepath.
+		// There's no reason for other DataSources to need this codepath.
 		return datasourceNotSupportedErr()
 	}
 	if r.Method != http.MethodPost {
diff --git a/internal/paths.go b/internal/paths.go
index 1a180ca..2a7ec3e 100644
--- a/internal/paths.go
+++ b/internal/paths.go
@@ -31,7 +31,7 @@
 	}
 	var r []string
 	for p := fullPath; p != "." && p != "/"; p = path.Dir(p) {
-		if err := module.CheckImportPath(p); err != nil {
+		if err := module.CheckPath(p); err != nil {
 			continue
 		}
 		r = append(r, p)
diff --git a/internal/paths_test.go b/internal/paths_test.go
index fb0c25e..44427fc 100644
--- a/internal/paths_test.go
+++ b/internal/paths_test.go
@@ -39,6 +39,11 @@
 			"bitbucket.org/ok/sure/no$dollars/allowed",
 			[]string{"bitbucket.org/ok/sure"},
 		},
+		{
+			// A module path cannot end in "v1".
+			"k8s.io/klog/v1",
+			[]string{"k8s.io/klog", "k8s.io"},
+		},
 	} {
 		got := CandidateModulePaths(test.in)
 		if !cmp.Equal(got, test.want) {