diff --git a/gddo-server/crawl.go b/gddo-server/crawl.go index fb3daa00..d0a0645f 100644 --- a/gddo-server/crawl.go +++ b/gddo-server/crawl.go @@ -8,6 +8,7 @@ package main import ( "log" + "regexp" "strings" "time" @@ -15,6 +16,8 @@ import ( "github.com/golang/gddo/gosrc" ) +var testdataPat = regexp.MustCompile(`/testdata(?:/|$)`) + // crawlDoc fetches the package documentation from the VCS and updates the database. func crawlDoc(source string, importPath string, pdoc *doc.Package, hasSubdirs bool, nextCrawl time.Time) (*doc.Package, error) { message := []interface{}{source} @@ -45,6 +48,9 @@ func crawlDoc(source string, importPath string, pdoc *doc.Package, hasSubdirs bo } else if blocked, e := db.IsBlocked(importPath); blocked && e == nil { pdoc = nil err = gosrc.NotFoundError{Message: "blocked."} + } else if testdataPat.MatchString(importPath) { + pdoc = nil + err = gosrc.NotFoundError{Message: "testdata."} } else { var pdocNew *doc.Package pdocNew, err = doc.Get(httpClient, importPath, etag) diff --git a/gosrc/path.go b/gosrc/path.go index e10529ac..6575df82 100644 --- a/gosrc/path.go +++ b/gosrc/path.go @@ -18,7 +18,7 @@ var validHost = regexp.MustCompile(`^[-a-z0-9]+(?:\.[-a-z0-9]+)+$`) var validPathElement = regexp.MustCompile(`^[-A-Za-z0-9~+_][-A-Za-z0-9_.]*$`) func isValidPathElement(s string) bool { - return validPathElement.MatchString(s) && s != "testdata" + return validPathElement.MatchString(s) } // IsValidRemotePath returns true if importPath is structurally valid for "go get". diff --git a/gosrc/path_test.go b/gosrc/path_test.go index 8cad7a7c..be9fc0f6 100644 --- a/gosrc/path_test.go +++ b/gosrc/path_test.go @@ -28,7 +28,6 @@ var badImportPaths = []string{ ".bar", "favicon.ico", "exmpple.com", - "github.com/user/repo/testdata/x", "github.com/user/repo/.ignore/x", }