mirror of
https://github.com/golang/go
synced 2024-11-22 02:44:39 -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:
parent
237ee39269
commit
ec9967ff11
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user