From b466a3654d8f78723805eb13ac0312a5d1fdc865 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Wed, 19 Jan 2022 12:08:15 +0800 Subject: [PATCH] convert alias to lowercase when check --- models/repo.go | 14 ++++++++------ routers/repo/setting.go | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/models/repo.go b/models/repo.go index f32b42ef7..0ae395c78 100755 --- a/models/repo.go +++ b/models/repo.go @@ -222,9 +222,10 @@ type Repository struct { CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` - Hot int64 `xorm:"-"` - Active int64 `xorm:"-"` - Alias string + Hot int64 `xorm:"-"` + Active int64 `xorm:"-"` + Alias string `xorm:"INDEX"` + LowerAlias string `xorm:"INDEX"` } // SanitizedOriginalURL returns a sanitized OriginalURL @@ -942,10 +943,10 @@ func isRepositoryExist(e Engine, u *User, repoName string, alias string) (bool, cond = cond.And(builder.Eq{"owner_id": u.ID}) if alias != "" { subCon := builder.NewCond() - subCon = subCon.Or(builder.Eq{"alias": alias}, builder.Eq{"lower_name": repoName}) + subCon = subCon.Or(builder.Eq{"lower_alias": strings.ToLower(alias)}, builder.Eq{"lower_name": strings.ToLower(repoName)}) cond = cond.And(subCon) } else { - cond = cond.And(builder.Eq{"lower_name": repoName}) + cond = cond.And(builder.Eq{"lower_name": strings.ToLower(repoName)}) } count, err := e.Where(cond).Count(&Repository{}) return count > 0 || com.IsDir(RepoPath(u.Name, repoName)), err @@ -964,7 +965,7 @@ func IsRepositoryAliasExist(u *User, alias string) (bool, error) { func isRepositoryAliasExist(e Engine, u *User, alias string) (bool, error) { var cond = builder.NewCond() cond = cond.And(builder.Eq{"owner_id": u.ID}) - cond = cond.And(builder.Eq{"alias": alias}) + cond = cond.And(builder.Eq{"lower_alias": strings.ToLower(alias)}) count, err := e.Where(cond).Count(&Repository{}) return count > 0, err } @@ -1108,6 +1109,7 @@ func IsUsableRepoAlias(name string) error { // CreateRepository creates a repository for the user/organization. func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error) { + repo.LowerAlias = strings.ToLower(repo.Alias) if err = IsUsableRepoName(repo.Name); err != nil { return err } diff --git a/routers/repo/setting.go b/routers/repo/setting.go index cebaefdf2..b9b7b20f6 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -72,7 +72,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { newAlias := form.Alias // Check if repository alias has been changed. - if repo.Alias != newAlias { + if strings.ToLower(repo.Alias) != strings.ToLower(newAlias) { //check new alias is available or not if err := models.IsRepositoryAliasAvailable(ctx.Repo.Owner, newAlias); err != nil { ctx.Data["Err_Alias"] = true @@ -125,6 +125,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { repo.Website = form.Website repo.IsTemplate = form.Template repo.Alias = newAlias + repo.LowerAlias = strings.ToLower(newAlias) // Visibility of forked repository is forced sync with base repository. if repo.IsFork {