mirror of
https://github.com/golang/go
synced 2024-11-23 21:40:05 -07:00
cmd/go: fix vendor-related index out of range panic on bad file tree
Fixes #12156. Change-Id: I2d71163b98bcc770147eb9e78dc551a9d0b5b817 Reviewed-on: https://go-review.googlesource.com/13674 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
d2cf46dedf
commit
9e26cde786
@ -416,7 +416,7 @@ func vendoredImportPath(parent *Package, path string) (found string, searched []
|
||||
return path, nil
|
||||
}
|
||||
dir := filepath.Clean(parent.Dir)
|
||||
root := filepath.Clean(parent.Root)
|
||||
root := filepath.Join(parent.Root, "src")
|
||||
if !hasFilePathPrefix(dir, root) || len(dir) <= len(root) || dir[len(root)] != filepath.Separator {
|
||||
fatalf("invalid vendoredImportPath: dir=%q root=%q separator=%q", dir, root, string(filepath.Separator))
|
||||
}
|
||||
|
3
src/cmd/go/testdata/testvendor2/src/p/p.go
vendored
Normal file
3
src/cmd/go/testdata/testvendor2/src/p/p.go
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
package p
|
||||
|
||||
import "x"
|
1
src/cmd/go/testdata/testvendor2/vendor/x/x.go
vendored
Normal file
1
src/cmd/go/testdata/testvendor2/vendor/x/x.go
vendored
Normal file
@ -0,0 +1 @@
|
||||
package x
|
@ -244,3 +244,15 @@ func TestVendorList(t *testing.T) {
|
||||
tg.run("list", "-f", `{{join .XTestImports "\n"}}`, "github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx3")
|
||||
tg.grepStdout("go-get-issue-11864/vendor/vendor.org/tx3", "did not find vendor-expanded tx3")
|
||||
}
|
||||
|
||||
func TestVendor12156(t *testing.T) {
|
||||
// Former index out of range panic.
|
||||
tg := testgo(t)
|
||||
defer tg.cleanup()
|
||||
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/testvendor2"))
|
||||
tg.setenv("GO15VENDOREXPERIMENT", "1")
|
||||
tg.cd(filepath.Join(tg.pwd(), "testdata/testvendor2/src/p"))
|
||||
tg.runFail("build", "p.go")
|
||||
tg.grepStderrNot("panic", "panicked")
|
||||
tg.grepStderr(`cannot find package "x"`, "wrong error")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user