fix panic in term range search
if min and max are the same term and the term is in dictionary and both in and max are set to exclusive then we would panic attempting to access element -1 of a slice. now, after trimming the slice, we recheck that the length is > 0
This commit is contained in:
parent
15cb7a505a
commit
87f693fc57
|
@ -64,6 +64,10 @@ func NewTermRangeSearcher(indexReader index.IndexReader,
|
|||
|
||||
if !*inclusiveMin && min != nil && string(min) == terms[0] {
|
||||
terms = terms[1:]
|
||||
// check again, as we might have removed only entry
|
||||
if len(terms) < 1 {
|
||||
return NewMatchNoneSearcher(indexReader)
|
||||
}
|
||||
}
|
||||
|
||||
// if our term list included the max, it would be the last item
|
||||
|
|
|
@ -157,6 +157,15 @@ func TestTermRangeSearch(t *testing.T) {
|
|||
inclusiveMax: true,
|
||||
want: nil,
|
||||
},
|
||||
// min and max same (and term exists), both exlusive
|
||||
{
|
||||
min: []byte("marty"),
|
||||
max: []byte("marty"),
|
||||
field: "name",
|
||||
inclusiveMin: false,
|
||||
inclusiveMax: false,
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
Loading…
Reference in New Issue