Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
Imporve handling of testdata directories
Browse files Browse the repository at this point in the history
Move the "testdata" directory filter from gosrc.IsValidRemotePath to the
crawler. This fixes the incorrect error in #250.
  • Loading branch information
garyburd committed Mar 2, 2015
1 parent 4ada458 commit 15ba11b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 6 additions & 0 deletions gddo-server/crawl.go
Expand Up @@ -8,13 +8,16 @@ package main

import (
"log"
"regexp"
"strings"
"time"

"github.com/golang/gddo/doc"
"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}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gosrc/path.go
Expand Up @@ -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".
Expand Down
1 change: 0 additions & 1 deletion gosrc/path_test.go
Expand Up @@ -28,7 +28,6 @@ var badImportPaths = []string{
".bar",
"favicon.ico",
"exmpple.com",
"github.com/user/repo/testdata/x",
"github.com/user/repo/.ignore/x",
}

Expand Down

0 comments on commit 15ba11b

Please sign in to comment.