Browse Source

autofix: fix check for empty string (#6804)

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
deepsource-autofix[bot] 3 years ago
parent
commit
deec3516d5

+ 1 - 1
internal/auth/ldap/config.go

@@ -193,7 +193,7 @@ func bindUser(l *ldap.Conn, userDN, passwd string) error {
 // searchEntry searches an LDAP source if an entry (name, passwd) is valid and in the specific filter.
 // searchEntry searches an LDAP source if an entry (name, passwd) is valid and in the specific filter.
 func (c *Config) searchEntry(name, passwd string, directBind bool) (string, string, string, string, bool, bool) {
 func (c *Config) searchEntry(name, passwd string, directBind bool) (string, string, string, string, bool, bool) {
 	// See https://tools.ietf.org/search/rfc4513#section-5.1.2
 	// See https://tools.ietf.org/search/rfc4513#section-5.1.2
-	if len(passwd) == 0 {
+	if passwd == "" {
 		log.Trace("authentication failed for '%s' with empty password", name)
 		log.Trace("authentication failed for '%s' with empty password", name)
 		return "", "", "", "", false, false
 		return "", "", "", "", false, false
 	}
 	}

+ 2 - 2
internal/auth/ldap/provider.go

@@ -32,10 +32,10 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
 		return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}}
 		return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}}
 	}
 	}
 
 
-	if len(username) == 0 {
+	if username == "" {
 		username = login
 		username = login
 	}
 	}
-	if len(email) == 0 {
+	if email == "" {
 		email = fmt.Sprintf("%s@localhost", username)
 		email = fmt.Sprintf("%s@localhost", username)
 	}
 	}
 
 

+ 4 - 4
internal/cmd/hook.go

@@ -63,7 +63,7 @@ var (
 )
 )
 
 
 func runHookPreReceive(c *cli.Context) error {
 func runHookPreReceive(c *cli.Context) error {
-	if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {
+	if os.Getenv("SSH_ORIGINAL_COMMAND") == "" {
 		return nil
 		return nil
 	}
 	}
 	setup(c, "pre-receive.log", true)
 	setup(c, "pre-receive.log", true)
@@ -156,7 +156,7 @@ func runHookPreReceive(c *cli.Context) error {
 }
 }
 
 
 func runHookUpdate(c *cli.Context) error {
 func runHookUpdate(c *cli.Context) error {
-	if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {
+	if os.Getenv("SSH_ORIGINAL_COMMAND") == "" {
 		return nil
 		return nil
 	}
 	}
 	setup(c, "update.log", false)
 	setup(c, "update.log", false)
@@ -164,7 +164,7 @@ func runHookUpdate(c *cli.Context) error {
 	args := c.Args()
 	args := c.Args()
 	if len(args) != 3 {
 	if len(args) != 3 {
 		fail("Arguments received are not equal to three", "Arguments received are not equal to three")
 		fail("Arguments received are not equal to three", "Arguments received are not equal to three")
-	} else if len(args[0]) == 0 {
+	} else if args[0] == "" {
 		fail("First argument 'refName' is empty", "First argument 'refName' is empty")
 		fail("First argument 'refName' is empty", "First argument 'refName' is empty")
 	}
 	}
 
 
@@ -190,7 +190,7 @@ func runHookUpdate(c *cli.Context) error {
 }
 }
 
 
 func runHookPostReceive(c *cli.Context) error {
 func runHookPostReceive(c *cli.Context) error {
-	if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {
+	if os.Getenv("SSH_ORIGINAL_COMMAND") == "" {
 		return nil
 		return nil
 	}
 	}
 	setup(c, "post-receive.log", true)
 	setup(c, "post-receive.log", true)

+ 6 - 8
internal/cmd/serv.go

@@ -125,13 +125,11 @@ func checkDeployKey(key *db.PublicKey, repo *db.Repository) {
 	}
 	}
 }
 }
 
 
-var (
-	allowedCommands = map[string]db.AccessMode{
-		"git-upload-pack":    db.AccessModeRead,
-		"git-upload-archive": db.AccessModeRead,
-		"git-receive-pack":   db.AccessModeWrite,
-	}
-)
+var allowedCommands = map[string]db.AccessMode{
+	"git-upload-pack":    db.AccessModeRead,
+	"git-upload-archive": db.AccessModeRead,
+	"git-receive-pack":   db.AccessModeWrite,
+}
 
 
 func runServ(c *cli.Context) error {
 func runServ(c *cli.Context) error {
 	setup(c, "serv.log", true)
 	setup(c, "serv.log", true)
@@ -146,7 +144,7 @@ func runServ(c *cli.Context) error {
 	}
 	}
 
 
 	sshCmd := os.Getenv("SSH_ORIGINAL_COMMAND")
 	sshCmd := os.Getenv("SSH_ORIGINAL_COMMAND")
-	if len(sshCmd) == 0 {
+	if sshCmd == "" {
 		println("Hi there, You've successfully authenticated, but Gogs does not provide shell access.")
 		println("Hi there, You've successfully authenticated, but Gogs does not provide shell access.")
 		println("If this is unexpected, please log in with password and setup Gogs under another user.")
 		println("If this is unexpected, please log in with password and setup Gogs under another user.")
 		return nil
 		return nil

+ 1 - 1
internal/context/auth.go

@@ -117,7 +117,7 @@ func authenticatedUserID(c *macaron.Context, sess session.Store) (_ int64, isTok
 		if len(tokenSHA) <= 0 {
 		if len(tokenSHA) <= 0 {
 			tokenSHA = c.Query("access_token")
 			tokenSHA = c.Query("access_token")
 		}
 		}
-		if len(tokenSHA) == 0 {
+		if tokenSHA == "" {
 			// Well, check with header again.
 			// Well, check with header again.
 			auHead := c.Req.Header.Get("Authorization")
 			auHead := c.Req.Header.Get("Authorization")
 			if len(auHead) > 0 {
 			if len(auHead) > 0 {

+ 2 - 2
internal/context/repo.go

@@ -284,7 +284,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
 
 
 		// If not branch selected, try default one.
 		// If not branch selected, try default one.
 		// If default branch doesn't exists, fall back to some other branch.
 		// If default branch doesn't exists, fall back to some other branch.
-		if len(c.Repo.BranchName) == 0 {
+		if c.Repo.BranchName == "" {
 			if len(c.Repo.Repository.DefaultBranch) > 0 && gitRepo.HasBranch(c.Repo.Repository.DefaultBranch) {
 			if len(c.Repo.Repository.DefaultBranch) > 0 && gitRepo.HasBranch(c.Repo.Repository.DefaultBranch) {
 				c.Repo.BranchName = c.Repo.Repository.DefaultBranch
 				c.Repo.BranchName = c.Repo.Repository.DefaultBranch
 			} else if len(branches) > 0 {
 			} else if len(branches) > 0 {
@@ -322,7 +322,7 @@ func RepoRef() macaron.Handler {
 		}
 		}
 
 
 		// Get default branch.
 		// Get default branch.
-		if len(c.Params("*")) == 0 {
+		if c.Params("*") == "" {
 			refName = c.Repo.Repository.DefaultBranch
 			refName = c.Repo.Repository.DefaultBranch
 			if !c.Repo.GitRepo.HasBranch(refName) {
 			if !c.Repo.GitRepo.HasBranch(refName) {
 				branches, err := c.Repo.GitRepo.Branches()
 				branches, err := c.Repo.GitRepo.Branches()

+ 3 - 3
internal/db/action.go

@@ -325,7 +325,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
 			ref = strings.TrimSpace(ref)
 			ref = strings.TrimSpace(ref)
 			ref = strings.TrimRightFunc(ref, issueIndexTrimRight)
 			ref = strings.TrimRightFunc(ref, issueIndexTrimRight)
 
 
-			if len(ref) == 0 {
+			if ref == "" {
 				continue
 				continue
 			}
 			}
 
 
@@ -368,7 +368,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
 			ref = ref[strings.IndexByte(ref, byte(' '))+1:]
 			ref = ref[strings.IndexByte(ref, byte(' '))+1:]
 			ref = strings.TrimRightFunc(ref, issueIndexTrimRight)
 			ref = strings.TrimRightFunc(ref, issueIndexTrimRight)
 
 
-			if len(ref) == 0 {
+			if ref == "" {
 				continue
 				continue
 			}
 			}
 
 
@@ -407,7 +407,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
 			ref = ref[strings.IndexByte(ref, byte(' '))+1:]
 			ref = ref[strings.IndexByte(ref, byte(' '))+1:]
 			ref = strings.TrimRightFunc(ref, issueIndexTrimRight)
 			ref = strings.TrimRightFunc(ref, issueIndexTrimRight)
 
 
-			if len(ref) == 0 {
+			if ref == "" {
 				continue
 				continue
 			}
 			}
 
 

+ 1 - 1
internal/db/comment.go

@@ -364,7 +364,7 @@ func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content stri
 
 
 // CreateRefComment creates a commit reference comment to issue.
 // CreateRefComment creates a commit reference comment to issue.
 func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
 func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
-	if len(commitSHA) == 0 {
+	if commitSHA == "" {
 		return fmt.Errorf("cannot create reference with empty commit SHA")
 		return fmt.Errorf("cannot create reference with empty commit SHA")
 	}
 	}
 
 

+ 1 - 1
internal/db/issue_label.go

@@ -33,7 +33,7 @@ func GetLabelTemplateFile(name string) ([][2]string, error) {
 	list := make([][2]string, 0, len(lines))
 	list := make([][2]string, 0, len(lines))
 	for i := 0; i < len(lines); i++ {
 	for i := 0; i < len(lines); i++ {
 		line := strings.TrimSpace(lines[i])
 		line := strings.TrimSpace(lines[i])
-		if len(line) == 0 {
+		if line == "" {
 			continue
 			continue
 		}
 		}
 
 

+ 2 - 4
internal/db/org.go

@@ -16,9 +16,7 @@ import (
 	"gogs.io/gogs/internal/errutil"
 	"gogs.io/gogs/internal/errutil"
 )
 )
 
 
-var (
-	ErrOrgNotExist = errors.New("Organization does not exist")
-)
+var ErrOrgNotExist = errors.New("Organization does not exist")
 
 
 // IsOwnedBy returns true if given user is in the owner team.
 // IsOwnedBy returns true if given user is in the owner team.
 func (org *User) IsOwnedBy(userID int64) bool {
 func (org *User) IsOwnedBy(userID int64) bool {
@@ -174,7 +172,7 @@ func CreateOrganization(org, owner *User) (err error) {
 
 
 // GetOrgByName returns organization by given name.
 // GetOrgByName returns organization by given name.
 func GetOrgByName(name string) (*User, error) {
 func GetOrgByName(name string) (*User, error) {
-	if len(name) == 0 {
+	if name == "" {
 		return nil, ErrOrgNotExist
 		return nil, ErrOrgNotExist
 	}
 	}
 	u := &User{
 	u := &User{

+ 2 - 2
internal/db/org_team.go

@@ -255,7 +255,7 @@ func IsUsableTeamName(name string) error {
 // NewTeam creates a record of new team.
 // NewTeam creates a record of new team.
 // It's caller's responsibility to assign organization ID.
 // It's caller's responsibility to assign organization ID.
 func NewTeam(t *Team) error {
 func NewTeam(t *Team) error {
-	if len(t.Name) == 0 {
+	if t.Name == "" {
 		return errors.New("empty team name")
 		return errors.New("empty team name")
 	} else if t.OrgID == 0 {
 	} else if t.OrgID == 0 {
 		return errors.New("OrgID is not assigned")
 		return errors.New("OrgID is not assigned")
@@ -364,7 +364,7 @@ func GetTeamsByOrgID(orgID int64) ([]*Team, error) {
 
 
 // UpdateTeam updates information of team.
 // UpdateTeam updates information of team.
 func UpdateTeam(t *Team, authChanged bool) (err error) {
 func UpdateTeam(t *Team, authChanged bool) (err error) {
-	if len(t.Name) == 0 {
+	if t.Name == "" {
 		return errors.New("empty team name")
 		return errors.New("empty team name")
 	}
 	}
 
 

+ 1 - 1
internal/db/release.go

@@ -109,7 +109,7 @@ func (r *Release) APIFormat() *api.Release {
 
 
 // IsReleaseExist returns true if release with given tag name already exists.
 // IsReleaseExist returns true if release with given tag name already exists.
 func IsReleaseExist(repoID int64, tagName string) (bool, error) {
 func IsReleaseExist(repoID int64, tagName string) (bool, error) {
-	if len(tagName) == 0 {
+	if tagName == "" {
 		return false, nil
 		return false, nil
 	}
 	}
 
 

+ 2 - 2
internal/db/repo.go

@@ -217,7 +217,7 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	switch colName {
 	case "default_branch":
 	case "default_branch":
 		// FIXME: use db migration to solve all at once.
 		// FIXME: use db migration to solve all at once.
-		if len(repo.DefaultBranch) == 0 {
+		if repo.DefaultBranch == "" {
 			repo.DefaultBranch = "master"
 			repo.DefaultBranch = "master"
 		}
 		}
 	case "num_closed_issues":
 	case "num_closed_issues":
@@ -227,7 +227,7 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
 	case "num_closed_milestones":
 	case "num_closed_milestones":
 		repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
 		repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
 	case "external_tracker_style":
 	case "external_tracker_style":
-		if len(repo.ExternalTrackerStyle) == 0 {
+		if repo.ExternalTrackerStyle == "" {
 			repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
 			repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
 		}
 		}
 	case "created_unix":
 	case "created_unix":

+ 1 - 1
internal/db/ssh_key.go

@@ -147,7 +147,7 @@ func parseKeyString(content string) (string, error) {
 		if err != nil {
 		if err != nil {
 			return "", fmt.Errorf("extractTypeFromBase64Key: %v", err)
 			return "", fmt.Errorf("extractTypeFromBase64Key: %v", err)
 		}
 		}
-		if len(keyType) == 0 {
+		if keyType == "" {
 			keyType = t
 			keyType = t
 		} else if keyType != t {
 		} else if keyType != t {
 			return "", fmt.Errorf("key type and content does not match: %s - %s", keyType, t)
 			return "", fmt.Errorf("key type and content does not match: %s - %s", keyType, t)

+ 6 - 6
internal/db/user.go

@@ -222,7 +222,7 @@ func (u *User) CustomAvatarPath() string {
 // GenerateRandomAvatar generates a random avatar for user.
 // GenerateRandomAvatar generates a random avatar for user.
 func (u *User) GenerateRandomAvatar() error {
 func (u *User) GenerateRandomAvatar() error {
 	seed := u.Email
 	seed := u.Email
-	if len(seed) == 0 {
+	if seed == "" {
 		seed = u.Name
 		seed = u.Name
 	}
 	}
 
 
@@ -479,7 +479,7 @@ func (u *User) IsMailable() bool {
 // If uid is presented, then check will rule out that one,
 // If uid is presented, then check will rule out that one,
 // it is used when update a user name in settings page.
 // it is used when update a user name in settings page.
 func IsUserExist(uid int64, name string) (bool, error) {
 func IsUserExist(uid int64, name string) (bool, error) {
-	if len(name) == 0 {
+	if name == "" {
 		return false, nil
 		return false, nil
 	}
 	}
 	return x.Where("id != ?", uid).Get(&User{LowerName: strings.ToLower(name)})
 	return x.Where("id != ?", uid).Get(&User{LowerName: strings.ToLower(name)})
@@ -729,7 +729,7 @@ func updateUser(e Engine, u *User) error {
 			return ErrEmailAlreadyUsed{args: errutil.Args{"email": u.Email}}
 			return ErrEmailAlreadyUsed{args: errutil.Args{"email": u.Email}}
 		}
 		}
 
 
-		if len(u.AvatarEmail) == 0 {
+		if u.AvatarEmail == "" {
 			u.AvatarEmail = u.Email
 			u.AvatarEmail = u.Email
 		}
 		}
 		u.Avatar = tool.HashEmail(u.AvatarEmail)
 		u.Avatar = tool.HashEmail(u.AvatarEmail)
@@ -955,7 +955,7 @@ func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
 // GetUserByName returns a user by given name.
 // GetUserByName returns a user by given name.
 // Deprecated: Use Users.GetByUsername instead.
 // Deprecated: Use Users.GetByUsername instead.
 func GetUserByName(name string) (*User, error) {
 func GetUserByName(name string) (*User, error) {
-	if len(name) == 0 {
+	if name == "" {
 		return nil, ErrUserNotExist{args: map[string]interface{}{"name": name}}
 		return nil, ErrUserNotExist{args: map[string]interface{}{"name": name}}
 	}
 	}
 	u := &User{LowerName: strings.ToLower(name)}
 	u := &User{LowerName: strings.ToLower(name)}
@@ -1035,7 +1035,7 @@ func ValidateCommitsWithEmails(oldCommits []*git.Commit) []*UserCommit {
 // GetUserByEmail returns the user object by given e-mail if exists.
 // GetUserByEmail returns the user object by given e-mail if exists.
 // Deprecated: Use Users.GetByEmail instead.
 // Deprecated: Use Users.GetByEmail instead.
 func GetUserByEmail(email string) (*User, error) {
 func GetUserByEmail(email string) (*User, error) {
-	if len(email) == 0 {
+	if email == "" {
 		return nil, ErrUserNotExist{args: map[string]interface{}{"email": email}}
 		return nil, ErrUserNotExist{args: map[string]interface{}{"email": email}}
 	}
 	}
 
 
@@ -1074,7 +1074,7 @@ type SearchUserOptions struct {
 // SearchUserByName takes keyword and part of user name to search,
 // SearchUserByName takes keyword and part of user name to search,
 // it returns results in given range and number of total results.
 // it returns results in given range and number of total results.
 func SearchUserByName(opts *SearchUserOptions) (users []*User, _ int64, _ error) {
 func SearchUserByName(opts *SearchUserOptions) (users []*User, _ int64, _ error) {
-	if len(opts.Keyword) == 0 {
+	if opts.Keyword == "" {
 		return users, 0, nil
 		return users, 0, nil
 	}
 	}
 	opts.Keyword = strings.ToLower(opts.Keyword)
 	opts.Keyword = strings.ToLower(opts.Keyword)

+ 1 - 1
internal/db/user_mail.go

@@ -57,7 +57,7 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) {
 }
 }
 
 
 func isEmailUsed(e Engine, email string) (bool, error) {
 func isEmailUsed(e Engine, email string) (bool, error) {
-	if len(email) == 0 {
+	if email == "" {
 		return true, nil
 		return true, nil
 	}
 	}
 
 

+ 1 - 1
internal/db/users.go

@@ -278,7 +278,7 @@ func (ErrUserNotExist) NotFound() bool {
 func (db *users) GetByEmail(email string) (*User, error) {
 func (db *users) GetByEmail(email string) (*User, error) {
 	email = strings.ToLower(email)
 	email = strings.ToLower(email)
 
 
-	if len(email) == 0 {
+	if email == "" {
 		return nil, ErrUserNotExist{args: errutil.Args{"email": email}}
 		return nil, ErrUserNotExist{args: errutil.Args{"email": email}}
 	}
 	}
 
 

+ 2 - 2
internal/db/webhook.go

@@ -470,7 +470,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) {
 		t.DeliveredString = time.Unix(0, t.Delivered).Format("2006-01-02 15:04:05 MST")
 		t.DeliveredString = time.Unix(0, t.Delivered).Format("2006-01-02 15:04:05 MST")
 
 
 	case "request_content":
 	case "request_content":
-		if len(t.RequestContent) == 0 {
+		if t.RequestContent == "" {
 			return
 			return
 		}
 		}
 
 
@@ -480,7 +480,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) {
 		}
 		}
 
 
 	case "response_content":
 	case "response_content":
-		if len(t.ResponseContent) == 0 {
+		if t.ResponseContent == "" {
 			return
 			return
 		}
 		}
 
 

+ 1 - 1
internal/db/wiki.go

@@ -122,7 +122,7 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes
 		return fmt.Errorf("WriteFile: %v", err)
 		return fmt.Errorf("WriteFile: %v", err)
 	}
 	}
 
 
-	if len(message) == 0 {
+	if message == "" {
 		message = "Update page '" + title + "'"
 		message = "Update page '" + title + "'"
 	}
 	}
 	if err = git.RepoAdd(localPath, git.AddOptions{All: true}); err != nil {
 	if err = git.RepoAdd(localPath, git.AddOptions{All: true}); err != nil {

+ 1 - 1
internal/email/message.go

@@ -138,7 +138,7 @@ func (s *Sender) Send(from string, to []string, msg io.WriterTo) error {
 
 
 	if !opts.DisableHELO {
 	if !opts.DisableHELO {
 		hostname := opts.HELOHostname
 		hostname := opts.HELOHostname
-		if len(hostname) == 0 {
+		if hostname == "" {
 			hostname, err = os.Hostname()
 			hostname, err = os.Hostname()
 			if err != nil {
 			if err != nil {
 				return err
 				return err

+ 2 - 2
internal/form/form.go

@@ -57,7 +57,7 @@ func Assign(form interface{}, data map[string]interface{}) {
 		// Allow ignored fields in the struct
 		// Allow ignored fields in the struct
 		if fieldName == "-" {
 		if fieldName == "-" {
 			continue
 			continue
-		} else if len(fieldName) == 0 {
+		} else if fieldName == "" {
 			fieldName = com.ToSnakeCase(field.Name)
 			fieldName = com.ToSnakeCase(field.Name)
 		}
 		}
 
 
@@ -119,7 +119,7 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro
 			data["Err_"+field.Name] = true
 			data["Err_"+field.Name] = true
 
 
 			trName := field.Tag.Get("locale")
 			trName := field.Tag.Get("locale")
-			if len(trName) == 0 {
+			if trName == "" {
 				trName = l.Tr("form." + field.Name)
 				trName = l.Tr("form." + field.Name)
 			} else {
 			} else {
 				trName = l.Tr(trName)
 				trName = l.Tr(trName)

+ 2 - 2
internal/httplib/httplib.go

@@ -169,7 +169,7 @@ func (r *Request) Headers() http.Header {
 // Set the protocol version for incoming requests.
 // Set the protocol version for incoming requests.
 // Client requests always use HTTP/1.1.
 // Client requests always use HTTP/1.1.
 func (r *Request) SetProtocolVersion(vers string) *Request {
 func (r *Request) SetProtocolVersion(vers string) *Request {
-	if len(vers) == 0 {
+	if vers == "" {
 		vers = "HTTP/1.1"
 		vers = "HTTP/1.1"
 	}
 	}
 
 
@@ -339,7 +339,7 @@ func (r *Request) getResponse() (*http.Response, error) {
 		Jar:       jar,
 		Jar:       jar,
 	}
 	}
 
 
-	if len(r.setting.UserAgent) > 0 && len(r.req.Header.Get("User-Agent")) == 0 {
+	if len(r.setting.UserAgent) > 0 && r.req.Header.Get("User-Agent") == "" {
 		r.req.Header.Set("User-Agent", r.setting.UserAgent)
 		r.req.Header.Set("User-Agent", r.setting.UserAgent)
 	}
 	}
 
 

+ 2 - 2
internal/markup/markup.go

@@ -70,7 +70,7 @@ func FindAllMentions(content string) []string {
 // cutoutVerbosePrefix cutouts URL prefix including sub-path to
 // cutoutVerbosePrefix cutouts URL prefix including sub-path to
 // return a clean unified string of request URL path.
 // return a clean unified string of request URL path.
 func cutoutVerbosePrefix(prefix string) string {
 func cutoutVerbosePrefix(prefix string) string {
-	if len(prefix) == 0 || prefix[0] != '/' {
+	if prefix == "" || prefix[0] != '/' {
 		return prefix
 		return prefix
 	}
 	}
 	count := 0
 	count := 0
@@ -186,7 +186,7 @@ func wrapImgWithLink(urlPrefix string, buf *bytes.Buffer, token html.Token) {
 	}
 	}
 
 
 	// Skip in case the "src" is empty
 	// Skip in case the "src" is empty
-	if len(src) == 0 {
+	if src == "" {
 		buf.WriteString(token.String())
 		buf.WriteString(token.String())
 		return
 		return
 	}
 	}

+ 1 - 1
internal/route/admin/repos.go

@@ -34,7 +34,7 @@ func Repos(c *context.Context) {
 	)
 	)
 
 
 	keyword := c.Query("q")
 	keyword := c.Query("q")
-	if len(keyword) == 0 {
+	if keyword == "" {
 		repos, err = db.Repositories(page, conf.UI.Admin.RepoPagingNum)
 		repos, err = db.Repositories(page, conf.UI.Admin.RepoPagingNum)
 		if err != nil {
 		if err != nil {
 			c.Error(err, "list repositories")
 			c.Error(err, "list repositories")

+ 1 - 1
internal/route/api/v1/misc/markdown.go

@@ -12,7 +12,7 @@ import (
 )
 )
 
 
 func Markdown(c *context.APIContext, form api.MarkdownOption) {
 func Markdown(c *context.APIContext, form api.MarkdownOption) {
-	if len(form.Text) == 0 {
+	if form.Text == "" {
 		_, _ = c.Write([]byte(""))
 		_, _ = c.Write([]byte(""))
 		return
 		return
 	}
 	}

+ 1 - 1
internal/route/api/v1/repo/issue.go

@@ -142,7 +142,7 @@ func EditIssue(c *context.APIContext, form api.EditIssueOption) {
 
 
 	if c.Repo.IsWriter() && form.Assignee != nil &&
 	if c.Repo.IsWriter() && form.Assignee != nil &&
 		(issue.Assignee == nil || issue.Assignee.LowerName != strings.ToLower(*form.Assignee)) {
 		(issue.Assignee == nil || issue.Assignee.LowerName != strings.ToLower(*form.Assignee)) {
-		if len(*form.Assignee) == 0 {
+		if *form.Assignee == "" {
 			issue.AssigneeID = 0
 			issue.AssigneeID = 0
 		} else {
 		} else {
 			assignee, err := db.GetUserByName(*form.Assignee)
 			assignee, err := db.GetUserByName(*form.Assignee)

+ 2 - 2
internal/route/home.go

@@ -38,7 +38,7 @@ func Home(c *context.Context) {
 
 
 	// Check auto-login.
 	// Check auto-login.
 	uname := c.GetCookie(conf.Security.CookieUsername)
 	uname := c.GetCookie(conf.Security.CookieUsername)
-	if len(uname) != 0 {
+	if uname != "" {
 		c.Redirect(conf.Server.Subpath + "/user/login")
 		c.Redirect(conf.Server.Subpath + "/user/login")
 		return
 		return
 	}
 	}
@@ -104,7 +104,7 @@ func RenderUserSearch(c *context.Context, opts *UserSearchOptions) {
 	)
 	)
 
 
 	keyword := c.Query("q")
 	keyword := c.Query("q")
-	if len(keyword) == 0 {
+	if keyword == "" {
 		users, err = opts.Ranger(page, opts.PageSize)
 		users, err = opts.Ranger(page, opts.PageSize)
 		if err != nil {
 		if err != nil {
 			c.Error(err, "ranger")
 			c.Error(err, "ranger")

+ 3 - 3
internal/route/install.go

@@ -221,7 +221,7 @@ func InstallPost(c *context.Context, f form.Install) {
 	conf.Database.SSLMode = f.SSLMode
 	conf.Database.SSLMode = f.SSLMode
 	conf.Database.Path = f.DbPath
 	conf.Database.Path = f.DbPath
 
 
-	if conf.Database.Type == "sqlite3" && len(conf.Database.Path) == 0 {
+	if conf.Database.Type == "sqlite3" && conf.Database.Path == "" {
 		c.FormErr("DbPath")
 		c.FormErr("DbPath")
 		c.RenderWithErr(c.Tr("install.err_empty_db_path"), INSTALL, &f)
 		c.RenderWithErr(c.Tr("install.err_empty_db_path"), INSTALL, &f)
 		return
 		return
@@ -280,14 +280,14 @@ func InstallPost(c *context.Context, f form.Install) {
 	}
 	}
 
 
 	// Check logic loophole between disable self-registration and no admin account.
 	// Check logic loophole between disable self-registration and no admin account.
-	if f.DisableRegistration && len(f.AdminName) == 0 {
+	if f.DisableRegistration && f.AdminName == "" {
 		c.FormErr("Services", "Admin")
 		c.FormErr("Services", "Admin")
 		c.RenderWithErr(c.Tr("install.no_admin_and_disable_registration"), INSTALL, f)
 		c.RenderWithErr(c.Tr("install.no_admin_and_disable_registration"), INSTALL, f)
 		return
 		return
 	}
 	}
 
 
 	// Check admin password.
 	// Check admin password.
-	if len(f.AdminName) > 0 && len(f.AdminPasswd) == 0 {
+	if len(f.AdminName) > 0 && f.AdminPasswd == "" {
 		c.FormErr("Admin", "AdminPasswd")
 		c.FormErr("Admin", "AdminPasswd")
 		c.RenderWithErr(c.Tr("install.err_empty_admin_password"), INSTALL, f)
 		c.RenderWithErr(c.Tr("install.err_empty_admin_password"), INSTALL, f)
 		return
 		return

+ 2 - 2
internal/route/repo/commit.go

@@ -25,7 +25,7 @@ const (
 func RefCommits(c *context.Context) {
 func RefCommits(c *context.Context) {
 	c.Data["PageIsViewFiles"] = true
 	c.Data["PageIsViewFiles"] = true
 	switch {
 	switch {
-	case len(c.Repo.TreePath) == 0:
+	case c.Repo.TreePath == "":
 		Commits(c)
 		Commits(c)
 	case c.Repo.TreePath == "search":
 	case c.Repo.TreePath == "search":
 		SearchCommits(c)
 		SearchCommits(c)
@@ -85,7 +85,7 @@ func SearchCommits(c *context.Context) {
 	c.Data["PageIsCommits"] = true
 	c.Data["PageIsCommits"] = true
 
 
 	keyword := c.Query("q")
 	keyword := c.Query("q")
-	if len(keyword) == 0 {
+	if keyword == "" {
 		c.Redirect(c.Repo.RepoLink + "/commits/" + c.Repo.BranchName)
 		c.Redirect(c.Repo.RepoLink + "/commits/" + c.Repo.BranchName)
 		return
 		return
 	}
 	}

+ 6 - 6
internal/route/repo/editor.go

@@ -33,7 +33,7 @@ const (
 // getParentTreeFields returns list of parent tree names and corresponding tree paths
 // getParentTreeFields returns list of parent tree names and corresponding tree paths
 // based on given tree path.
 // based on given tree path.
 func getParentTreeFields(treePath string) (treeNames, treePaths []string) {
 func getParentTreeFields(treePath string) (treeNames, treePaths []string) {
-	if len(treePath) == 0 {
+	if treePath == "" {
 		return treeNames, treePaths
 		return treeNames, treePaths
 	}
 	}
 
 
@@ -158,7 +158,7 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
 		return
 		return
 	}
 	}
 
 
-	if len(f.TreePath) == 0 {
+	if f.TreePath == "" {
 		c.FormErr("TreePath")
 		c.FormErr("TreePath")
 		c.RenderWithErr(c.Tr("repo.editor.filename_cannot_be_empty"), tmplEditorEdit, &f)
 		c.RenderWithErr(c.Tr("repo.editor.filename_cannot_be_empty"), tmplEditorEdit, &f)
 		return
 		return
@@ -248,7 +248,7 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
 	}
 	}
 
 
 	message := strings.TrimSpace(f.CommitSummary)
 	message := strings.TrimSpace(f.CommitSummary)
-	if len(message) == 0 {
+	if message == "" {
 		if isNewFile {
 		if isNewFile {
 			message = c.Tr("repo.editor.add", f.TreePath)
 			message = c.Tr("repo.editor.add", f.TreePath)
 		} else {
 		} else {
@@ -362,7 +362,7 @@ func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
 	}
 	}
 
 
 	message := strings.TrimSpace(f.CommitSummary)
 	message := strings.TrimSpace(f.CommitSummary)
-	if len(message) == 0 {
+	if message == "" {
 		message = c.Tr("repo.editor.delete", c.Repo.TreePath)
 		message = c.Tr("repo.editor.delete", c.Repo.TreePath)
 	}
 	}
 
 
@@ -481,7 +481,7 @@ func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
 	}
 	}
 
 
 	message := strings.TrimSpace(f.CommitSummary)
 	message := strings.TrimSpace(f.CommitSummary)
-	if len(message) == 0 {
+	if message == "" {
 		message = c.Tr("repo.editor.upload_files_to_dir", f.TreePath)
 		message = c.Tr("repo.editor.upload_files_to_dir", f.TreePath)
 	}
 	}
 
 
@@ -555,7 +555,7 @@ func UploadFileToServer(c *context.Context) {
 }
 }
 
 
 func RemoveUploadFileFromServer(c *context.Context, f form.RemoveUploadFile) {
 func RemoveUploadFileFromServer(c *context.Context, f form.RemoveUploadFile) {
-	if len(f.File) == 0 {
+	if f.File == "" {
 		c.Status(http.StatusNoContent)
 		c.Status(http.StatusNoContent)
 		return
 		return
 	}
 	}

+ 1 - 1
internal/route/repo/http.go

@@ -106,7 +106,7 @@ func HTTPContexter() macaron.Handler {
 
 
 		// Handle HTTP Basic Authentication
 		// Handle HTTP Basic Authentication
 		authHead := c.Req.Header.Get("Authorization")
 		authHead := c.Req.Header.Get("Authorization")
-		if len(authHead) == 0 {
+		if authHead == "" {
 			askCredentials(c, http.StatusUnauthorized, "")
 			askCredentials(c, http.StatusUnauthorized, "")
 			return
 			return
 		}
 		}

+ 5 - 5
internal/route/repo/issue.go

@@ -700,7 +700,7 @@ func UpdateIssueTitle(c *context.Context) {
 	}
 	}
 
 
 	title := c.QueryTrim("title")
 	title := c.QueryTrim("title")
-	if len(title) == 0 {
+	if title == "" {
 		c.Status(http.StatusNoContent)
 		c.Status(http.StatusNoContent)
 		return
 		return
 	}
 	}
@@ -903,7 +903,7 @@ func NewComment(c *context.Context, f form.CreateComment) {
 	}()
 	}()
 
 
 	// Fix #321: Allow empty comments, as long as we have attachments.
 	// Fix #321: Allow empty comments, as long as we have attachments.
-	if len(f.Content) == 0 && len(attachments) == 0 {
+	if f.Content == "" && len(attachments) == 0 {
 		return
 		return
 	}
 	}
 
 
@@ -933,7 +933,7 @@ func UpdateCommentContent(c *context.Context) {
 
 
 	oldContent := comment.Content
 	oldContent := comment.Content
 	comment.Content = c.Query("content")
 	comment.Content = c.Query("content")
-	if len(comment.Content) == 0 {
+	if comment.Content == "" {
 		c.JSONSuccess(map[string]interface{}{
 		c.JSONSuccess(map[string]interface{}{
 			"content": "",
 			"content": "",
 		})
 		})
@@ -1127,7 +1127,7 @@ func NewMilestonePost(c *context.Context, f form.CreateMilestone) {
 		return
 		return
 	}
 	}
 
 
-	if len(f.Deadline) == 0 {
+	if f.Deadline == "" {
 		f.Deadline = "9999-12-31"
 		f.Deadline = "9999-12-31"
 	}
 	}
 	deadline, err := time.ParseInLocation("2006-01-02", f.Deadline, time.Local)
 	deadline, err := time.ParseInLocation("2006-01-02", f.Deadline, time.Local)
@@ -1183,7 +1183,7 @@ func EditMilestonePost(c *context.Context, f form.CreateMilestone) {
 		return
 		return
 	}
 	}
 
 
-	if len(f.Deadline) == 0 {
+	if f.Deadline == "" {
 		f.Deadline = "9999-12-31"
 		f.Deadline = "9999-12-31"
 	}
 	}
 	deadline, err := time.ParseInLocation("2006-01-02", f.Deadline, time.Local)
 	deadline, err := time.ParseInLocation("2006-01-02", f.Deadline, time.Local)

+ 1 - 1
internal/route/repo/release.go

@@ -293,7 +293,7 @@ func EditReleasePost(c *context.Context, f form.EditRelease) {
 		attachments = f.Files
 		attachments = f.Files
 	}
 	}
 
 
-	isPublish := rel.IsDraft && len(f.Draft) == 0
+	isPublish := rel.IsDraft && f.Draft == ""
 	rel.Title = f.Title
 	rel.Title = f.Title
 	rel.Note = f.Content
 	rel.Note = f.Content
 	rel.IsDraft = len(f.Draft) > 0
 	rel.IsDraft = len(f.Draft) > 0

+ 1 - 1
internal/route/repo/setting.go

@@ -378,7 +378,7 @@ func SettingsCollaboration(c *context.Context) {
 
 
 func SettingsCollaborationPost(c *context.Context) {
 func SettingsCollaborationPost(c *context.Context) {
 	name := strings.ToLower(c.Query("collaborator"))
 	name := strings.ToLower(c.Query("collaborator"))
-	if len(name) == 0 || c.Repo.Owner.LowerName == name {
+	if name == "" || c.Repo.Owner.LowerName == name {
 		c.Redirect(conf.Server.Subpath + c.Req.URL.Path)
 		c.Redirect(conf.Server.Subpath + c.Req.URL.Path)
 		return
 		return
 	}
 	}

+ 1 - 1
internal/route/repo/view.go

@@ -177,7 +177,7 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 			var output bytes.Buffer
 			var output bytes.Buffer
 			lines := strings.Split(fileContent, "\n")
 			lines := strings.Split(fileContent, "\n")
 			// Remove blank line at the end of file
 			// Remove blank line at the end of file
-			if len(lines) > 0 && len(lines[len(lines)-1]) == 0 {
+			if len(lines) > 0 && lines[len(lines)-1] == "" {
 				lines = lines[:len(lines)-1]
 				lines = lines[:len(lines)-1]
 			}
 			}
 			for index, line := range lines {
 			for index, line := range lines {

+ 2 - 2
internal/route/repo/wiki.go

@@ -75,7 +75,7 @@ func renderWikiPage(c *context.Context, isViewPage bool) (*git.Repository, strin
 	}
 	}
 
 
 	pageURL := c.Params(":page")
 	pageURL := c.Params(":page")
-	if len(pageURL) == 0 {
+	if pageURL == "" {
 		pageURL = "Home"
 		pageURL = "Home"
 	}
 	}
 	c.Data["PageURL"] = pageURL
 	c.Data["PageURL"] = pageURL
@@ -253,7 +253,7 @@ func EditWikiPost(c *context.Context, f form.NewWiki) {
 
 
 func DeleteWikiPagePost(c *context.Context) {
 func DeleteWikiPagePost(c *context.Context) {
 	pageURL := c.Params(":page")
 	pageURL := c.Params(":page")
-	if len(pageURL) == 0 {
+	if pageURL == "" {
 		pageURL = "Home"
 		pageURL = "Home"
 	}
 	}
 
 

+ 4 - 4
internal/route/user/auth.go

@@ -38,7 +38,7 @@ func AutoLogin(c *context.Context) (bool, error) {
 	}
 	}
 
 
 	uname := c.GetCookie(conf.Security.CookieUsername)
 	uname := c.GetCookie(conf.Security.CookieUsername)
-	if len(uname) == 0 {
+	if uname == "" {
 		return false, nil
 		return false, nil
 	}
 	}
 
 
@@ -384,7 +384,7 @@ func SignUpPost(c *context.Context, cpt *captcha.Captcha, f form.Register) {
 
 
 func Activate(c *context.Context) {
 func Activate(c *context.Context) {
 	code := c.Query("code")
 	code := c.Query("code")
-	if len(code) == 0 {
+	if code == "" {
 		c.Data["IsActivatePage"] = true
 		c.Data["IsActivatePage"] = true
 		if c.User.IsActive {
 		if c.User.IsActive {
 			c.NotFound()
 			c.NotFound()
@@ -515,7 +515,7 @@ func ResetPasswd(c *context.Context) {
 	c.Title("auth.reset_password")
 	c.Title("auth.reset_password")
 
 
 	code := c.Query("code")
 	code := c.Query("code")
-	if len(code) == 0 {
+	if code == "" {
 		c.NotFound()
 		c.NotFound()
 		return
 		return
 	}
 	}
@@ -528,7 +528,7 @@ func ResetPasswdPost(c *context.Context) {
 	c.Title("auth.reset_password")
 	c.Title("auth.reset_password")
 
 
 	code := c.Query("code")
 	code := c.Query("code")
-	if len(code) == 0 {
+	if code == "" {
 		c.NotFound()
 		c.NotFound()
 		return
 		return
 	}
 	}

+ 2 - 2
internal/template/template.go

@@ -93,7 +93,7 @@ func FuncMap() []template.FuncMap {
 				return t.Format("Jan 02, 2006")
 				return t.Format("Jan 02, 2006")
 			},
 			},
 			"SubStr": func(str string, start, length int) string {
 			"SubStr": func(str string, start, length int) string {
-				if len(str) == 0 {
+				if str == "" {
 					return ""
 					return ""
 				}
 				}
 				end := start + length
 				end := start + length
@@ -186,7 +186,7 @@ func RenderCommitMessage(full bool, msg, urlPrefix string, metas map[string]stri
 		return ""
 		return ""
 	} else if !full {
 	} else if !full {
 		return msgLines[0]
 		return msgLines[0]
-	} else if numLines == 1 || (numLines >= 2 && len(msgLines[1]) == 0) {
+	} else if numLines == 1 || (numLines >= 2 && msgLines[1] == "") {
 		// First line is a header, standalone or followed by empty line
 		// First line is a header, standalone or followed by empty line
 		header := fmt.Sprintf("<h3>%s</h3>", msgLines[0])
 		header := fmt.Sprintf("<h3>%s</h3>", msgLines[0])
 		if numLines >= 2 {
 		if numLines >= 2 {

+ 2 - 2
internal/tool/tool.go

@@ -143,10 +143,10 @@ func AvatarLink(email string) (url string) {
 			log.Warn("AvatarLink.LibravatarService.FromEmail [%s]: %v", email, err)
 			log.Warn("AvatarLink.LibravatarService.FromEmail [%s]: %v", email, err)
 		}
 		}
 	}
 	}
-	if len(url) == 0 && !conf.Picture.DisableGravatar {
+	if url == "" && !conf.Picture.DisableGravatar {
 		url = conf.Picture.GravatarSource + HashEmail(email) + "?d=identicon"
 		url = conf.Picture.GravatarSource + HashEmail(email) + "?d=identicon"
 	}
 	}
-	if len(url) == 0 {
+	if url == "" {
 		url = conf.Server.Subpath + "/img/avatar_default.png"
 		url = conf.Server.Subpath + "/img/avatar_default.png"
 	}
 	}
 	return url
 	return url