handle OR'd tags where the first tag matches nothing : assignment to nil map panic
This commit is contained in:
parent
185393d62d
commit
bd86e90174
2 changed files with 24 additions and 5 deletions
|
|
@ -40,19 +40,36 @@ func processQueries(tagmap map[string]Set, query Query) Set {
|
|||
|
||||
// initialize as first query
|
||||
q := query.Tags[0]
|
||||
// NOTE: clone so that we don't accidentally overwrite the incoming tagmap
|
||||
set = maps.Clone(tagmap[q])
|
||||
|
||||
// empty query
|
||||
// TODO: do I want to handle WILD and a tag? Actual regex?
|
||||
if query.Op == WILD && q == "" {
|
||||
if len(query.Tags) == 1 && query.Op == WILD && q == "" {
|
||||
// NOTE: this is all files with at least one tag and therefore of value:
|
||||
set.Union(slices.Collect(maps.Values(tagmap))...)
|
||||
return set
|
||||
}
|
||||
// no need for set logic in this case:
|
||||
if len(query.Tags) == 1 {
|
||||
return set
|
||||
}
|
||||
// if first query matches nothing: set will be nil and Union will fail:
|
||||
// TODO: solve this in set.Union by moving to pointer receiver.
|
||||
if set == nil {
|
||||
for _, t := range query.Tags {
|
||||
if tagmap[t] != nil {
|
||||
set = tagmap[t]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// all tagmap[q] are still nil:
|
||||
if set == nil {
|
||||
return set
|
||||
}
|
||||
|
||||
// NOTE: clone so that we don't accidentally overwrite the incoming tagmap
|
||||
set = maps.Clone(tagmap[q])
|
||||
// when queries < 2, this won't run
|
||||
for i := 1; i < len(query.Tags); i++ {
|
||||
for i := 0; i < len(query.Tags); i++ {
|
||||
q = query.Tags[i]
|
||||
switch query.Op {
|
||||
case OR:
|
||||
|
|
|
|||
Loading…
Reference in a new issue