From: Alex Brainman Date: Thu, 21 Sep 2017 02:33:11 +0000 (+1000) Subject: cmd/go: ignore empty path elements in GOPATH X-Git-Tag: go1.10beta1~1002 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=18b49db18e02c1590119eeda58673bf93c2e41c9;p=gostls13.git cmd/go: ignore empty path elements in GOPATH go command refuses to use GOPATH with empty path elements (like %GOPATH%=C:\go;). But environment variable change dialog on Windows 10 produces strings ending with ; (see issue #21928 for a picture). Just accept GOPATH with empty path elements, and ignore all empty path elements. Fixes #21928 Change-Id: I1d3c3a19274ed69204d29ae06c3e8ff8c57c1ca0 Reviewed-on: https://go-review.googlesource.com/65151 Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 1a47b72083..2145ffb275 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -1689,6 +1689,27 @@ func TestRejectRelativePathsInGOPATHCommandLinePackage(t *testing.T) { tg.grepStderr("GOPATH entry is relative", "expected an error message rejecting relative GOPATH entries") } +// Issue 21928. +func TestRejectBlankPathsInGOPATH(t *testing.T) { + tg := testgo(t) + defer tg.cleanup() + sep := string(filepath.ListSeparator) + tg.setenv("GOPATH", " "+sep+filepath.Join(tg.pwd(), "testdata")) + tg.runFail("build", "go-cmd-test") + tg.grepStderr("GOPATH entry is relative", "expected an error message rejecting relative GOPATH entries") +} + +// Issue 21928. +func TestIgnoreEmptyPathsInGOPATH(t *testing.T) { + tg := testgo(t) + defer tg.cleanup() + tg.creatingTemp("testdata/bin/go-cmd-test" + exeSuffix) + sep := string(filepath.ListSeparator) + tg.setenv("GOPATH", ""+sep+filepath.Join(tg.pwd(), "testdata")) + tg.run("install", "go-cmd-test") + tg.wantExecutable("testdata/bin/go-cmd-test"+exeSuffix, "go install go-cmd-test did not write to testdata/bin/go-cmd-test") +} + // Issue 4104. func TestGoTestWithPackageListedMultipleTimes(t *testing.T) { tg := testgo(t) diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index 75a46db98f..f5b64869ea 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -89,6 +89,11 @@ func main() { fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect\n", gopath) } else { for _, p := range filepath.SplitList(gopath) { + // Some GOPATHs have empty directory elements - ignore them. + // See issue 21928 for details. + if p == "" { + continue + } // Note: using HasPrefix instead of Contains because a ~ can appear // in the middle of directory elements, such as /tmp/git-1.8.2~rc3 // or C:\PROGRA~1. Only ~ as a path prefix has meaning to the shell.