Reviewers: rsc,
Message:
Hello rsc@golang.org (cc: golang-dev@googlegroups.com),
I'd like you to review this change to
https://code.google.com/p/go
Description:
go/build: reject empty strings in Import
Fixes issue 3889.
Please review this at http://codereview.appspot.com/6499102/
Affected files:
M src/pkg/go/build/build.go
M src/pkg/go/build/build_test.go
Index: src/pkg/go/build/build.go
===================================================================
--- a/src/pkg/go/build/build.go
+++ b/src/pkg/go/build/build.go
@@ -348,6 +348,9 @@
// *Package containing partial information.
//
func (ctxt *Context) Import(path string, srcDir string, mode ImportMode)
(*Package, error) {
+ if path == "" {
+ return nil, errors.New(`Can't import "".`)
+ }
p := &Package{
ImportPath: path,
}
Index: src/pkg/go/build/build_test.go
===================================================================
--- a/src/pkg/go/build/build_test.go
+++ b/src/pkg/go/build/build_test.go
@@ -61,6 +61,13 @@
}
}
+func TestEmptyImport(t *testing.T) {
+ _, err := Import("", Default.GOROOT, FindOnly)
+ if err == nil {
+ t.Fatal("Import should not accept empty strings.")
+ }
+}
+
func TestLocalDirectory(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {