mirror of https://github.com/go-gitea/gitea.git
Merge c5a2a1df16
into 24ce2058e8
commit
fbd80a8a68
|
@ -46,6 +46,8 @@ linters:
|
||||||
- pkg: gitea.com/go-chi/cache
|
- pkg: gitea.com/go-chi/cache
|
||||||
desc: do not use the go-chi cache package, use gitea's cache system
|
desc: do not use the go-chi cache package, use gitea's cache system
|
||||||
gocritic:
|
gocritic:
|
||||||
|
enabled-checks:
|
||||||
|
- equalFold
|
||||||
disabled-checks:
|
disabled-checks:
|
||||||
- ifElseChain
|
- ifElseChain
|
||||||
- singleCaseSwitch # Every time this occurred in the code, there was no other way.
|
- singleCaseSwitch # Every time this occurred in the code, there was no other way.
|
||||||
|
|
|
@ -166,7 +166,7 @@ func UpdateLanguageStats(ctx context.Context, repo *Repository, commitID string,
|
||||||
llang := strings.ToLower(lang)
|
llang := strings.ToLower(lang)
|
||||||
for _, s := range oldstats {
|
for _, s := range oldstats {
|
||||||
// Update already existing language
|
// Update already existing language
|
||||||
if strings.ToLower(s.Language) == llang {
|
if strings.EqualFold(s.Language, llang) {
|
||||||
s.CommitID = commitID
|
s.CommitID = commitID
|
||||||
s.IsPrimary = llang == topLang
|
s.IsPrimary = llang == topLang
|
||||||
s.Size = size
|
s.Size = size
|
||||||
|
|
|
@ -92,7 +92,7 @@ func (r *stripRenderer) processAutoLink(w io.Writer, link []byte) {
|
||||||
|
|
||||||
// Note: we're not attempting to match the URL scheme (http/https)
|
// Note: we're not attempting to match the URL scheme (http/https)
|
||||||
host := strings.ToLower(u.Host)
|
host := strings.ToLower(u.Host)
|
||||||
if host != "" && host != strings.ToLower(r.localhost.Host) {
|
if host != "" && !strings.EqualFold(host, r.localhost.Host) {
|
||||||
// Process out of band
|
// Process out of band
|
||||||
r.links = append(r.links, linkStr)
|
r.links = append(r.links, linkStr)
|
||||||
return
|
return
|
||||||
|
|
|
@ -88,7 +88,7 @@ func ParsePackage(r io.Reader) (*Package, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else if strings.ToLower(hd.Name) == "readme.md" {
|
} else if strings.EqualFold(hd.Name, "readme.md") {
|
||||||
data, err := io.ReadAll(tr)
|
data, err := io.ReadAll(tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -62,11 +62,11 @@ func (c logCompression) IsValid() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c logCompression) IsNone() bool {
|
func (c logCompression) IsNone() bool {
|
||||||
return strings.ToLower(string(c)) == "none"
|
return strings.EqualFold(string(c), "none")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c logCompression) IsZstd() bool {
|
func (c logCompression) IsZstd() bool {
|
||||||
return c == "" || strings.ToLower(string(c)) == "zstd"
|
return c == "" || strings.EqualFold(string(c), "zstd")
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadActionsFrom(rootCfg ConfigProvider) error {
|
func loadActionsFrom(rootCfg ConfigProvider) error {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
func SliceContainsString(slice []string, target string, insensitive ...bool) bool {
|
func SliceContainsString(slice []string, target string, insensitive ...bool) bool {
|
||||||
if len(insensitive) != 0 && insensitive[0] {
|
if len(insensitive) != 0 && insensitive[0] {
|
||||||
target = strings.ToLower(target)
|
target = strings.ToLower(target)
|
||||||
return slices.ContainsFunc(slice, func(t string) bool { return strings.ToLower(t) == target })
|
return slices.ContainsFunc(slice, func(t string) bool { return strings.EqualFold(t, target) })
|
||||||
}
|
}
|
||||||
|
|
||||||
return slices.Contains(slice, target)
|
return slices.Contains(slice, target)
|
||||||
|
|
|
@ -59,7 +59,7 @@ func TimeEstimateParse(timeStr string) (int64, error) {
|
||||||
unit := timeStr[match[4]:match[5]]
|
unit := timeStr[match[4]:match[5]]
|
||||||
found := false
|
found := false
|
||||||
for _, u := range timeStrGlobalVars().units {
|
for _, u := range timeStrGlobalVars().units {
|
||||||
if strings.ToLower(unit) == u.name {
|
if strings.EqualFold(unit, u.name) {
|
||||||
total += amount * u.num
|
total += amount * u.num
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
|
|
|
@ -145,7 +145,7 @@ func repoAssignment() func(ctx *context.APIContext) {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check if the user is the same as the repository owner.
|
// Check if the user is the same as the repository owner.
|
||||||
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
|
if ctx.IsSigned && strings.EqualFold(ctx.Doer.LowerName, userName) {
|
||||||
owner = ctx.Doer
|
owner = ctx.Doer
|
||||||
} else {
|
} else {
|
||||||
owner, err = user_model.GetUserByName(ctx, userName)
|
owner, err = user_model.GetUserByName(ctx, userName)
|
||||||
|
|
|
@ -276,7 +276,7 @@ func GetRepoPermissions(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/forbidden"
|
// "$ref": "#/responses/forbidden"
|
||||||
|
|
||||||
collaboratorUsername := ctx.PathParam("collaborator")
|
collaboratorUsername := ctx.PathParam("collaborator")
|
||||||
if !ctx.Doer.IsAdmin && ctx.Doer.LowerName != strings.ToLower(collaboratorUsername) && !ctx.IsUserRepoAdmin() {
|
if !ctx.Doer.IsAdmin && !strings.EqualFold(ctx.Doer.LowerName, collaboratorUsername) && !ctx.IsUserRepoAdmin() {
|
||||||
ctx.APIError(http.StatusForbidden, "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own")
|
ctx.APIError(http.StatusForbidden, "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -669,7 +669,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
newRepoName = *opts.Name
|
newRepoName = *opts.Name
|
||||||
}
|
}
|
||||||
// Check if repository name has been changed and not just a case change
|
// Check if repository name has been changed and not just a case change
|
||||||
if repo.LowerName != strings.ToLower(newRepoName) {
|
if !strings.EqualFold(repo.LowerName, newRepoName) {
|
||||||
if err := repo_service.ChangeRepositoryName(ctx, ctx.Doer, repo, newRepoName); err != nil {
|
if err := repo_service.ChangeRepositoryName(ctx, ctx.Doer, repo, newRepoName); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case repo_model.IsErrRepoAlreadyExist(err):
|
case repo_model.IsErrRepoAlreadyExist(err):
|
||||||
|
|
|
@ -109,7 +109,7 @@ func InfoOAuth(ctx *context.Context) {
|
||||||
var accessTokenScope auth.AccessTokenScope
|
var accessTokenScope auth.AccessTokenScope
|
||||||
if auHead := ctx.Req.Header.Get("Authorization"); auHead != "" {
|
if auHead := ctx.Req.Header.Get("Authorization"); auHead != "" {
|
||||||
auths := strings.Fields(auHead)
|
auths := strings.Fields(auHead)
|
||||||
if len(auths) == 2 && (auths[0] == "token" || strings.ToLower(auths[0]) == "bearer") {
|
if len(auths) == 2 && (auths[0] == "token" || strings.EqualFold(auths[0], "bearer")) {
|
||||||
accessTokenScope, _ = auth_service.GetOAuthAccessTokenScopeAndUserID(ctx, auths[1])
|
accessTokenScope, _ = auth_service.GetOAuthAccessTokenScopeAndUserID(ctx, auths[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -796,7 +796,7 @@ func cleanUploadFileName(name string) string {
|
||||||
name = util.PathJoinRel(name)
|
name = util.PathJoinRel(name)
|
||||||
// Git disallows any filenames to have a .git directory in them.
|
// Git disallows any filenames to have a .git directory in them.
|
||||||
for _, part := range strings.Split(name, "/") {
|
for _, part := range strings.Split(name, "/") {
|
||||||
if strings.ToLower(part) == ".git" {
|
if strings.EqualFold(part, ".git") {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ func handleSettingsPostUpdate(ctx *context.Context) {
|
||||||
|
|
||||||
newRepoName := form.RepoName
|
newRepoName := form.RepoName
|
||||||
// Check if repository name has been changed.
|
// Check if repository name has been changed.
|
||||||
if repo.LowerName != strings.ToLower(newRepoName) {
|
if !strings.EqualFold(repo.LowerName, newRepoName) {
|
||||||
// Close the GitRepo if open
|
// Close the GitRepo if open
|
||||||
if ctx.Repo.GitRepo != nil {
|
if ctx.Repo.GitRepo != nil {
|
||||||
ctx.Repo.GitRepo.Close()
|
ctx.Repo.GitRepo.Close()
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore
|
||||||
}
|
}
|
||||||
|
|
||||||
auths := strings.SplitN(baHead, " ", 2)
|
auths := strings.SplitN(baHead, " ", 2)
|
||||||
if len(auths) != 2 || (strings.ToLower(auths[0]) != "basic") {
|
if len(auths) != 2 || (!strings.EqualFold(auths[0], "basic")) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ func parseToken(req *http.Request) (string, bool) {
|
||||||
// check header token
|
// check header token
|
||||||
if auHead := req.Header.Get("Authorization"); auHead != "" {
|
if auHead := req.Header.Get("Authorization"); auHead != "" {
|
||||||
auths := strings.Fields(auHead)
|
auths := strings.Fields(auHead)
|
||||||
if len(auths) == 2 && (auths[0] == "token" || strings.ToLower(auths[0]) == "bearer") {
|
if len(auths) == 2 && (auths[0] == "token" || strings.EqualFold(auths[0], "bearer")) {
|
||||||
return auths[1], true
|
return auths[1], true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,7 +241,7 @@ func (source *Source) listLdapGroupMemberships(l *ldap.Conn, uid string, applyGr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (source *Source) getUserAttributeListedInGroup(entry *ldap.Entry) string {
|
func (source *Source) getUserAttributeListedInGroup(entry *ldap.Entry) string {
|
||||||
if strings.ToLower(source.UserUID) == "dn" {
|
if strings.EqualFold(source.UserUID, "dn") {
|
||||||
return entry.DN
|
return entry.DN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,7 @@ func OrgAssignment(opts OrgAssignmentOptions) func(ctx *Context) {
|
||||||
if len(teamName) > 0 {
|
if len(teamName) > 0 {
|
||||||
teamExists := false
|
teamExists := false
|
||||||
for _, team := range ctx.Org.Teams {
|
for _, team := range ctx.Org.Teams {
|
||||||
if team.LowerName == strings.ToLower(teamName) {
|
if strings.EqualFold(team.LowerName, teamName) {
|
||||||
teamExists = true
|
teamExists = true
|
||||||
ctx.Org.Team = team
|
ctx.Org.Team = team
|
||||||
ctx.Org.IsTeamMember = true
|
ctx.Org.IsTeamMember = true
|
||||||
|
|
|
@ -393,7 +393,7 @@ func RepoAssignment(ctx *Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user is the same as the repository owner
|
// Check if the user is the same as the repository owner
|
||||||
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
|
if ctx.IsSigned && strings.EqualFold(ctx.Doer.LowerName, userName) {
|
||||||
ctx.Repo.Owner = ctx.Doer
|
ctx.Repo.Owner = ctx.Doer
|
||||||
} else {
|
} else {
|
||||||
ctx.Repo.Owner, err = user_model.GetUserByName(ctx, userName)
|
ctx.Repo.Owner, err = user_model.GetUserByName(ctx, userName)
|
||||||
|
|
|
@ -61,7 +61,7 @@ func UserAssignmentAPI() func(ctx *APIContext) {
|
||||||
func userAssignment(ctx *Base, doer *user_model.User, errCb func(int, any)) (contextUser *user_model.User) {
|
func userAssignment(ctx *Base, doer *user_model.User, errCb func(int, any)) (contextUser *user_model.User) {
|
||||||
username := ctx.PathParam("username")
|
username := ctx.PathParam("username")
|
||||||
|
|
||||||
if doer != nil && doer.LowerName == strings.ToLower(username) {
|
if doer != nil && strings.EqualFold(doer.LowerName, username) {
|
||||||
contextUser = doer
|
contextUser = doer
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -140,7 +140,7 @@ func CleanUploadFileName(name string) string {
|
||||||
name = util.PathJoinRel(name)
|
name = util.PathJoinRel(name)
|
||||||
// Git disallows any filenames to have a .git directory in them.
|
// Git disallows any filenames to have a .git directory in them.
|
||||||
for _, part := range strings.Split(name, "/") {
|
for _, part := range strings.Split(name, "/") {
|
||||||
if strings.ToLower(part) == ".git" {
|
if strings.EqualFold(part, ".git") {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue