1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:24:41 -07:00

go/build: reject empty strings in Import

Fixes #3889.

R=rsc, adg
CC=golang-dev
https://golang.org/cl/6499102
This commit is contained in:
Francisco Souza 2012-09-13 10:25:35 -04:00 committed by Russ Cox
parent 237ee39269
commit ec9967ff11
2 changed files with 16 additions and 0 deletions

View File

@ -351,6 +351,9 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
p := &Package{
ImportPath: path,
}
if path == "" {
return p, fmt.Errorf("import %q: invalid import path", path)
}
var pkga string
var pkgerr error

View File

@ -61,6 +61,19 @@ func TestDotSlashImport(t *testing.T) {
}
}
func TestEmptyImport(t *testing.T) {
p, err := Import("", Default.GOROOT, FindOnly)
if err == nil {
t.Fatal(`Import("") returned nil error.`)
}
if p == nil {
t.Fatal(`Import("") returned nil package.`)
}
if p.ImportPath != "" {
t.Fatalf("ImportPath=%q, want %q.", p.ImportPath, "")
}
}
func TestLocalDirectory(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {