Commit 18b49db1 authored by Alex Brainman's avatar Alex Brainman

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 <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent e6358c79
......@@ -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)
......
......@@ -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.
......
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