1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:34:42 -07:00

internal/lsp/cache: correctly split env vars

We were using strings.Split on env vars, which did bad stuff when the
var contained an =, e.g. GOFLAGS=-tags=foo. Only split on the first =.

Irritatingly, this breaks only `go mod` commands, so almost nothing in
gopls failed, just organize imports and the `go.mod` code lens stuff.

Fixes golang/go#38669

Change-Id: I8d28c806b77a8df92100af1fa4fbcca5edf97cff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230560
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Heschi Kreinick 2020-04-28 14:06:04 -04:00
parent 006b16f6cf
commit e9a00ec821
2 changed files with 25 additions and 4 deletions

View File

@ -373,7 +373,7 @@ func (v *view) buildProcessEnv(ctx context.Context) (*imports.ProcessEnv, error)
}
}
for _, kv := range env {
split := strings.Split(kv, "=")
split := strings.SplitN(kv, "=", 2)
if len(split) < 2 {
continue
}

View File

@ -245,7 +245,7 @@ func TestHello(t *testing.T) {
}
`
func Test_Issue38267(t *testing.T) {
func TestIssue38267(t *testing.T) {
runner.Run(t, testPackage, func(t *testing.T, env *Env) {
env.OpenFile("lib_test.go")
env.Await(
@ -330,7 +330,7 @@ func TestMissingDependency(t *testing.T) {
})
}
func TestAdHocPackagesIssue_36951(t *testing.T) {
func TestAdHocPackages_Issue36951(t *testing.T) {
const adHoc = `
-- b/b.go --
package b
@ -345,7 +345,7 @@ func Hello() {
})
}
func TestNoGOPATHIssue_37984(t *testing.T) {
func TestNoGOPATH_Issue37984(t *testing.T) {
const missingImport = `
-- main.go --
package main
@ -362,3 +362,24 @@ func _() {
}
}, WithEnv("GOPATH="))
}
func TestEqualInEnv_Issue38669(t *testing.T) {
const missingImport = `
-- go.mod --
module mod.com
-- main.go --
package main
var _ = x.X
-- x/x.go --
package x
var X = 0
`
runner.Run(t, missingImport, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.OrganizeImports("main.go")
env.Await(EmptyDiagnostics("main.go"))
}, WithEnv("GOFLAGS=-tags=foo"))
}