added empty query checks
This commit is contained in:
parent
3b458f6ff1
commit
0e2b25e788
3 changed files with 31 additions and 5 deletions
13
filter.go
13
filter.go
|
|
@ -101,11 +101,12 @@ func NewQuery(s string) (q *Query, err error) {
|
|||
return
|
||||
}
|
||||
qm := make(map[string]struct{})
|
||||
fields := strings.Split(s, " ")
|
||||
fields := clearFields(s)
|
||||
if len(fields) == 0 {
|
||||
err = errors.New("query is empty")
|
||||
return
|
||||
}
|
||||
for _, v := range fields {
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
if q.l == undefined {
|
||||
l, ok := parseLogic(v)
|
||||
q.l = l
|
||||
|
|
@ -160,8 +161,10 @@ func NewQuery(s string) (q *Query, err error) {
|
|||
boolFunc(m[1]),
|
||||
})
|
||||
}
|
||||
if len(q.m) == 0 {
|
||||
if len(q.m) == 0 && q.s.enabled {
|
||||
q.s.only = true
|
||||
} else if len(q.m) == 0 {
|
||||
err = errors.New("query is empty")
|
||||
}
|
||||
if len(q.m) == 1 && q.l != not {
|
||||
q.l = or
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue