Skip to content

Commit

Permalink
matchtree: fix panic for missing files (#733)
Browse files Browse the repository at this point in the history
Previously, shards crashed for queries like "foo type:file" if foo was
not present.

Test plan:
updated e2e test
  • Loading branch information
stefanhengl authored Feb 1, 2024
1 parent fdc144f commit 746f388
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions matchtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,12 @@ func pruneMatchTree(mt matchTree) (matchTree, error) {
}
case *fileNameMatchTree:
mt.child, err = pruneMatchTree(mt.child)
if err != nil {
return nil, err
}
if mt.child == nil {
return nil, nil
}
case *boostMatchTree:
mt.child, err = pruneMatchTree(mt.child)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions web/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"

"github.com/sourcegraph/zoekt"
"github.com/sourcegraph/zoekt/query"
"github.com/sourcegraph/zoekt/rpc"
Expand Down Expand Up @@ -137,6 +138,9 @@ func TestBasic(t *testing.T) {
"/search?q=magic": {
`value=magic`,
},
"/search?q=foo+type:file": {
`value=foo`,
},
"/robots.txt": {
"disallow: /search",
},
Expand Down

0 comments on commit 746f388

Please sign in to comment.