mirror of https://github.com/golang/go.git
internal/lsp/source: handle empty strings in directoryFilters
Avoid a panic when a directoryFilters entry is empty. Fixes golang/go#51843 Change-Id: I50948894ce60d83441c3fc698c2e7d80d1d2b50e Reviewed-on: https://go-review.googlesource.com/c/tools/+/395675 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
parent
2536df952b
commit
4adadedf93
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package misc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "golang.org/x/tools/internal/lsp/regtest"
|
||||
)
|
||||
|
||||
func TestEmptyDirectoryFilters_Issue51843(t *testing.T) {
|
||||
const src = `
|
||||
-- go.mod --
|
||||
module mod.com
|
||||
|
||||
go 1.12
|
||||
-- main.go --
|
||||
package main
|
||||
|
||||
func main() {
|
||||
}
|
||||
`
|
||||
|
||||
WithOptions(
|
||||
EditorConfig{
|
||||
Settings: map[string]interface{}{
|
||||
"directoryFilters": []string{""},
|
||||
},
|
||||
},
|
||||
).Run(t, src, func(t *testing.T, env *Env) {
|
||||
// No need to do anything. Issue golang/go#51843 is triggered by the empty
|
||||
// directory filter above.
|
||||
})
|
||||
}
|
||||
|
|
@ -820,7 +820,7 @@ func (o *Options) set(name string, value interface{}, seen map[string]struct{})
|
|||
var filters []string
|
||||
for _, ifilter := range ifilters {
|
||||
filter := fmt.Sprint(ifilter)
|
||||
if filter[0] != '+' && filter[0] != '-' {
|
||||
if filter == "" || (filter[0] != '+' && filter[0] != '-') {
|
||||
result.errorf("invalid filter %q, must start with + or -", filter)
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue