Commit ec9967ff authored by Francisco Souza's avatar Francisco Souza Committed by Russ Cox

go/build: reject empty strings in Import

Fixes #3889.

R=rsc, adg
CC=golang-dev
https://golang.org/cl/6499102
parent 237ee392
......@@ -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
......
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment