diff options
author | Tyrone Yeh <siryeh@gmail.com> | 2022-07-29 00:58:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-28 18:58:04 +0200 |
commit | 8e3da0e27fd6da138b34b4a758c48f1d5e73df1f (patch) | |
tree | dc1fa84185839070c4fd6420a3f522fa4674d25f | |
parent | 2c108d20baa2b2fd0816ad2dfb3429d49a422f4e (diff) | |
download | gitea-8e3da0e27fd6da138b34b4a758c48f1d5e73df1f.tar.gz gitea-8e3da0e27fd6da138b34b4a758c48f1d5e73df1f.zip |
Modify milestone search keywords to be case insensitive again (#20513)
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: delvh <dev.lh@web.de>
-rw-r--r-- | models/db/common.go | 23 | ||||
-rw-r--r-- | models/issues/issue.go | 13 | ||||
-rw-r--r-- | models/issues/milestone.go | 2 |
3 files changed, 27 insertions, 11 deletions
diff --git a/models/db/common.go b/models/db/common.go new file mode 100644 index 0000000000..1a59a8b5c6 --- /dev/null +++ b/models/db/common.go @@ -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)} +} diff --git a/models/issues/issue.go b/models/issues/issue.go index 064f0d22ab..5bdb60f7c0 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -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" @@ -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), )), ), ), diff --git a/models/issues/milestone.go b/models/issues/milestone.go index c49799f391..1021938b20 100644 --- a/models/issues/milestone.go +++ b/models/issues/milestone.go @@ -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 |