1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-02 00:15:21 +02:00

[v11/forgejo] fix: skip empty tokens in SearchOptions.Tokens() (#8412)

backport of #8261 to v11

Co-authored-by: Danko Aleksejevs <danko@very.lv>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8412
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Shiny Nematoda <snematoda@noreply.codeberg.org>
Co-committed-by: Shiny Nematoda <snematoda@noreply.codeberg.org>
This commit is contained in:
Shiny Nematoda 2025-07-06 10:42:45 +02:00 committed by Earl Warren
parent 0dc2bed2dd
commit 86b6553f3a
5 changed files with 146 additions and 16 deletions

View file

@ -36,12 +36,9 @@ func (t *Tokenizer) next() (tk Token, err error) {
// skip all leading white space
for {
if r, _, err = t.in.ReadRune(); err == nil && r == ' ' {
//nolint:staticcheck,wastedassign // SA4006 the variable is used after the loop
r, _, err = t.in.ReadRune()
continue
if r, _, err = t.in.ReadRune(); err != nil || r != ' ' {
break
}
break
}
if err != nil {
return tk, err
@ -98,11 +95,17 @@ nextEnd:
// Tokenize the keyword
func (o *SearchOptions) Tokens() (tokens []Token, err error) {
if o.Keyword == "" {
return nil, nil
}
in := strings.NewReader(o.Keyword)
it := Tokenizer{in: in}
for token, err := it.next(); err == nil; token, err = it.next() {
tokens = append(tokens, token)
if token.Term != "" {
tokens = append(tokens, token)
}
}
if err != nil && err != io.EOF {
return nil, err