Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify milestone search keywords to be case insensitive again #20513

Merged
merged 6 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions models/db/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package db

import (
"strings"

"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"

"xorm.io/builder"
)

// BuildCaseInsensitiveLike returns a condition to check if the given value is like the given key case-insensitively.
// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
func BuildCaseInsensitiveLike(key, value string) builder.Cond {
if setting.Database.UseSQLite3 {
return builder.Like{"UPPER(" + key + ")", util.ToUpperASCII(value)}
}
return builder.Like{"UPPER(" + key + ")", strings.ToUpper(value)}
}
13 changes: 3 additions & 10 deletions models/issues/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
Expand Down Expand Up @@ -1903,23 +1902,17 @@ func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen,
func SearchIssueIDsByKeyword(ctx context.Context, kw string, repoIDs []int64, limit, start int) (int64, []int64, error) {
repoCond := builder.In("repo_id", repoIDs)
subQuery := builder.Select("id").From("issue").Where(repoCond)
// SQLite's UPPER function only transforms ASCII letters.
if setting.Database.UseSQLite3 {
kw = util.ToUpperASCII(kw)
} else {
kw = strings.ToUpper(kw)
}
cond := builder.And(
repoCond,
builder.Or(
builder.Like{"UPPER(name)", kw},
builder.Like{"UPPER(content)", kw},
db.BuildCaseInsensitiveLike("name", kw),
db.BuildCaseInsensitiveLike("content", kw),
builder.In("id", builder.Select("issue_id").
From("comment").
Where(builder.And(
builder.Eq{"type": CommentTypeComment},
builder.In("issue_id", subQuery),
builder.Like{"UPPER(content)", kw},
db.BuildCaseInsensitiveLike("content", kw),
)),
),
),
Expand Down
2 changes: 1 addition & 1 deletion models/issues/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (opts GetMilestonesOption) toCond() builder.Cond {
}

if len(opts.Name) != 0 {
cond = cond.And(builder.Like{"UPPER(name)", strings.ToUpper(opts.Name)})
cond = cond.And(db.BuildCaseInsensitiveLike("name", opts.Name))
}

return cond
Expand Down