Fix empty string comparison issues in the codebase (#16686)

Automatic Merge
Этот коммит содержится в:
Madhav Hugar
2021-01-25 11:15:17 +01:00
коммит произвёл GitHub
родитель 200a56fa5a
Коммит 94c24eea20
107 изменённых файлов: 368 добавлений и 368 удалений

Просмотреть файл

@@ -204,7 +204,7 @@ func (a *App) TestSiteURL(siteURL string) *model.AppError {
}
func (a *App) TestEmail(userId string, cfg *model.Config) *model.AppError {
if len(*cfg.EmailSettings.SMTPServer) == 0 {
if *cfg.EmailSettings.SMTPServer == "" {
return model.NewAppError("testEmail", "api.admin.test_email.missing_server", nil, utils.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusBadRequest)
}

Просмотреть файл

@@ -454,7 +454,7 @@ func (a *App) NotifyAndSetWarnMetricAck(warnMetricId string, sender *model.User,
}
if !forceAck {
if len(*a.Config().EmailSettings.SMTPServer) == 0 {
if *a.Config().EmailSettings.SMTPServer == "" {
return model.NewAppError("NotifyAndSetWarnMetricAck", "api.email.send_warn_metric_ack.missing_server.app_error", nil, utils.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusInternalServerError)
}
T := utils.GetUserTranslations(sender.Locale)

Просмотреть файл

@@ -22,7 +22,7 @@ const (
)
func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError {
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return model.NewAppError("SaveBrandImage", "api.admin.upload_brand_image.storage.app_error", nil, "", http.StatusNotImplemented)
}
@@ -69,7 +69,7 @@ func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError {
}
func (a *App) GetBrandImage() ([]byte, *model.AppError) {
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return nil, model.NewAppError("GetBrandImage", "api.admin.get_brand_image.storage.app_error", nil, "", http.StatusNotImplemented)
}

Просмотреть файл

@@ -175,7 +175,7 @@ func (a *App) CreateChannelWithUser(channel *model.Channel, userId string) (*mod
return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.direct_channel.app_error", nil, "", http.StatusBadRequest)
}
if len(channel.TeamId) == 0 {
if channel.TeamId == "" {
return nil, model.NewAppError("CreateChannelWithUser", "app.channel.create_channel.no_team_id.app_error", nil, "", http.StatusBadRequest)
}
@@ -839,7 +839,7 @@ func (a *App) GetChannelModerationsForChannel(channel *model.Channel) ([]*model.
}
var guestRole *model.Role
if len(guestRoleName) > 0 {
if guestRoleName != "" {
guestRole, err = a.GetRoleByName(guestRoleName)
if err != nil {
return nil, err
@@ -856,7 +856,7 @@ func (a *App) GetChannelModerationsForChannel(channel *model.Channel) ([]*model.
}
var higherScopedGuestRole *model.Role
if len(higherScopedGuestRoleName) > 0 {
if higherScopedGuestRoleName != "" {
higherScopedGuestRole, err = a.GetRoleByName(higherScopedGuestRoleName)
if err != nil {
return nil, err
@@ -879,7 +879,7 @@ func (a *App) PatchChannelModerationsForChannel(channel *model.Channel, channelM
}
var higherScopedGuestRole *model.Role
if len(higherScopedGuestRoleName) > 0 {
if higherScopedGuestRoleName != "" {
higherScopedGuestRole, err = a.GetRoleByName(higherScopedGuestRoleName)
if err != nil {
return nil, err
@@ -904,7 +904,7 @@ func (a *App) PatchChannelModerationsForChannel(channel *model.Channel, channelM
var scheme *model.Scheme
// Channel has no scheme so create one
if channel.SchemeId == nil || len(*channel.SchemeId) == 0 {
if channel.SchemeId == nil || *channel.SchemeId == "" {
scheme, err = a.CreateChannelScheme(channel)
if err != nil {
return nil, err
@@ -936,7 +936,7 @@ func (a *App) PatchChannelModerationsForChannel(channel *model.Channel, channelM
}
var guestRole *model.Role
if len(guestRoleName) > 0 {
if guestRoleName != "" {
guestRole, err = a.GetRoleByName(guestRoleName)
if err != nil {
return nil, err
@@ -2554,11 +2554,11 @@ func (a *App) ViewChannel(view *model.ChannelView, userId string, currentSession
channelIds := []string{}
if len(view.ChannelId) > 0 {
if view.ChannelId != "" {
channelIds = append(channelIds, view.ChannelId)
}
if len(view.PrevChannelId) > 0 {
if view.PrevChannelId != "" {
channelIds = append(channelIds, view.PrevChannelId)
}

Просмотреть файл

@@ -341,7 +341,7 @@ func (es *EmailService) SendInviteEmails(team *model.Team, senderName string, se
}
for _, invite := range invites {
if len(invite) > 0 {
if invite != "" {
subject := utils.T("api.templates.invite_subject",
map[string]interface{}{"SenderName": senderName,
"TeamDisplayName": team.DisplayName,
@@ -400,7 +400,7 @@ func (es *EmailService) sendGuestInviteEmails(team *model.Team, channels []*mode
}
for _, invite := range invites {
if len(invite) > 0 {
if invite != "" {
subject := utils.T("api.templates.invite_guest_subject",
map[string]interface{}{"SenderName": senderName,
"TeamDisplayName": team.DisplayName,

Просмотреть файл

@@ -39,7 +39,7 @@ func (a *App) CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartIma
return nil, model.NewAppError("UploadEmojiImage", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
}
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
}
@@ -96,7 +96,7 @@ func (a *App) UploadEmojiImage(id string, imageData *multipart.FileHeader) *mode
return model.NewAppError("UploadEmojiImage", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
}
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return model.NewAppError("UploadEmojiImage", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
}
@@ -181,7 +181,7 @@ func (a *App) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) {
return nil, model.NewAppError("GetEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
}
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
}
@@ -204,7 +204,7 @@ func (a *App) GetEmojiByName(emojiName string) (*model.Emoji, *model.AppError) {
return nil, model.NewAppError("GetEmojiByName", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
}
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return nil, model.NewAppError("GetEmojiByName", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
}

Просмотреть файл

@@ -498,7 +498,7 @@ func (a *App) UploadMultipartFiles(teamId string, channelId string, userId strin
// the same length. clientIds should either not be provided or have the same length as files and filenames.
// The provided files should be closed by the caller so that they are not leaked.
func (a *App) UploadFiles(teamId string, channelId string, userId string, files []io.ReadCloser, filenames []string, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError) {
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return nil, model.NewAppError("UploadFiles", "api.file.upload_file.storage.app_error", nil, "", http.StatusNotImplemented)
}
@@ -703,7 +703,7 @@ func (a *App) UploadFileX(channelId, name string, input io.Reader,
o(t)
}
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return nil, t.newAppError("api.file.upload_file.storage.app_error",
"", http.StatusNotImplemented)
}

Просмотреть файл

@@ -52,7 +52,7 @@ func (a *App) importScheme(data *SchemeImportData, dryRun bool) *model.AppError
scheme.Description = *data.Description
}
if len(scheme.Id) == 0 {
if scheme.Id == "" {
scheme, err = a.CreateScheme(scheme)
} else {
scheme, err = a.UpdateScheme(scheme)
@@ -146,7 +146,7 @@ func (a *App) importRole(data *RoleImportData, dryRun bool, isSchemeRole bool) *
role.SchemeManaged = false
}
if len(role.Id) == 0 {
if role.Id == "" {
_, err = a.CreateRole(role)
} else {
_, err = a.UpdateRole(role)
@@ -406,7 +406,7 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
roles = *data.Roles
hasUserRolesChanged = true
}
} else if len(user.Roles) == 0 {
} else if user.Roles == "" {
// Set SYSTEM_USER roles on newly created users by default.
if user.Roles != model.SYSTEM_USER_ROLE_ID {
roles = model.SYSTEM_USER_ROLE_ID
@@ -497,7 +497,7 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
return err
}
}
if len(password) > 0 {
if password != "" {
if err = a.UpdatePassword(user, password); err != nil {
return err
}
@@ -1078,7 +1078,7 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId str
reply.FileIds = append(reply.FileIds, fileID)
}
if len(reply.Id) == 0 {
if reply.Id == "" {
postsForCreateList = append(postsForCreateList, reply)
} else {
postsForOverwriteList = append(postsForOverwriteList, reply)
@@ -1333,7 +1333,7 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
post.FileIds = append(post.FileIds, fileID)
}
if len(post.Id) == 0 {
if post.Id == "" {
postsForCreateList = append(postsForCreateList, post)
postsForCreateMap[getPostStrID(post)] = line.LineNumber
} else {
@@ -1629,7 +1629,7 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
post.FileIds = append(post.FileIds, fileID)
}
if len(post.Id) == 0 {
if post.Id == "" {
postsForCreateList = append(postsForCreateList, post)
postsForCreateMap[getPostStrID(post)] = line.LineNumber
} else {

Просмотреть файл

@@ -36,7 +36,7 @@ func validateSchemeImportData(data *SchemeImportData) *model.AppError {
return model.NewAppError("BulkImport", "app.import.validate_scheme_import_data.name_invalid.error", nil, "", http.StatusBadRequest)
}
if data.DisplayName == nil || len(*data.DisplayName) == 0 || len(*data.DisplayName) > model.SCHEME_DISPLAY_NAME_MAX_LENGTH {
if data.DisplayName == nil || *data.DisplayName == "" || len(*data.DisplayName) > model.SCHEME_DISPLAY_NAME_MAX_LENGTH {
return model.NewAppError("BulkImport", "app.import.validate_scheme_import_data.display_name_invalid.error", nil, "", http.StatusBadRequest)
}
@@ -89,7 +89,7 @@ func validateRoleImportData(data *RoleImportData) *model.AppError {
return model.NewAppError("BulkImport", "app.import.validate_role_import_data.name_invalid.error", nil, "", http.StatusBadRequest)
}
if data.DisplayName == nil || len(*data.DisplayName) == 0 || len(*data.DisplayName) > model.ROLE_DISPLAY_NAME_MAX_LENGTH {
if data.DisplayName == nil || *data.DisplayName == "" || len(*data.DisplayName) > model.ROLE_DISPLAY_NAME_MAX_LENGTH {
return model.NewAppError("BulkImport", "app.import.validate_role_import_data.display_name_invalid.error", nil, "", http.StatusBadRequest)
}
@@ -207,7 +207,7 @@ func validateUserImportData(data *UserImportData) *model.AppError {
if data.Email == nil {
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.email_missing.error", nil, "", http.StatusBadRequest)
} else if len(*data.Email) == 0 || len(*data.Email) > model.USER_EMAIL_MAX_LENGTH {
} else if *data.Email == "" || len(*data.Email) > model.USER_EMAIL_MAX_LENGTH {
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.email_length.error", nil, "", http.StatusBadRequest)
}
@@ -223,14 +223,14 @@ func validateUserImportData(data *UserImportData) *model.AppError {
if str == nil {
return true
}
return len(*str) == 0
return *str == ""
}
if (!blank(data.AuthService) && blank(data.AuthData)) || (blank(data.AuthService) && !blank(data.AuthData)) {
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.auth_data_and_service_dependency.error", nil, "", http.StatusBadRequest)
}
if data.Password != nil && len(*data.Password) == 0 {
if data.Password != nil && *data.Password == "" {
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.password_length.error", nil, "", http.StatusBadRequest)
}
@@ -565,7 +565,7 @@ func validateEmojiImportData(data *EmojiImportData) *model.AppError {
return model.NewAppError("BulkImport", "app.import.validate_emoji_import_data.empty.error", nil, "", http.StatusBadRequest)
}
if data.Name == nil || len(*data.Name) == 0 {
if data.Name == nil || *data.Name == "" {
return model.NewAppError("BulkImport", "app.import.validate_emoji_import_data.name_missing.error", nil, "", http.StatusBadRequest)
}
@@ -573,7 +573,7 @@ func validateEmojiImportData(data *EmojiImportData) *model.AppError {
return err
}
if data.Image == nil || len(*data.Image) == 0 {
if data.Image == nil || *data.Image == "" {
return model.NewAppError("BulkImport", "app.import.validate_emoji_import_data.image_missing.error", nil, "", http.StatusBadRequest)
}

Просмотреть файл

@@ -116,7 +116,7 @@ func TestPostAction(t *testing.T) {
assert.Equal(t, request.TeamId, th.BasicTeam.Id)
assert.Equal(t, request.TeamName, th.BasicTeam.Name)
}
assert.True(t, len(request.TriggerId) > 0)
assert.True(t, request.TriggerId != "")
if request.Type == model.POST_ACTION_TYPE_SELECT {
assert.Equal(t, request.DataSource, "some_source")
assert.Equal(t, request.Context["selected_option"], "selected")

Просмотреть файл

@@ -29,7 +29,7 @@ func (a *App) CheckForClientSideCert(r *http.Request) (string, string, string) {
subject := r.Header.Get("X-SSL-Client-Cert-Subject-DN") // mapped to $ssl_client_s_dn from nginx
email := ""
if len(subject) > 0 {
if subject != "" {
for _, v := range strings.Split(subject, "/") {
kv := strings.Split(v, "=")
if len(kv) == 2 && kv[0] == "emailAddress" {
@@ -53,7 +53,7 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken, cwsToken
}
}()
if len(password) == 0 && !IsCWSLogin(a, cwsToken) {
if password == "" && !IsCWSLogin(a, cwsToken) {
return nil, model.NewAppError("AuthenticateUserForLogin", "api.user.login.blank_pwd.app_error", nil, "", http.StatusBadRequest)
}
@@ -175,7 +175,7 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
}}
session.GenerateCSRF()
if len(deviceId) > 0 {
if deviceId != "" {
a.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthMobileInDays)
// A special case where we logout of all other sessions with the same Id

Просмотреть файл

@@ -123,7 +123,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
}
// get users that have comment thread mentions enabled
if len(post.RootId) > 0 && parentPostList != nil {
if post.RootId != "" && parentPostList != nil {
for _, threadPost := range parentPostList.Posts {
profile := profileMap[threadPost.UserId]
if profile != nil && (profile.NotifyProps[model.COMMENTS_NOTIFY_PROP] == model.COMMENTS_NOTIFY_ANY || (profile.NotifyProps[model.COMMENTS_NOTIFY_PROP] == model.COMMENTS_NOTIFY_ROOT && threadPost.Id == parentPostList.Order[0])) {
@@ -596,7 +596,7 @@ func makeOutOfChannelMentionPost(sender *model.User, post *model.Post, outOfChan
}
if len(outOfGroupsUsers) == 1 {
if len(message) > 0 {
if message != "" {
message += "\n"
}
@@ -606,7 +606,7 @@ func makeOutOfChannelMentionPost(sender *model.User, post *model.Post, outOfChan
} else if len(outOfGroupsUsers) > 1 {
preliminary, final := splitAtFinal(ogUsernames)
if len(message) > 0 {
if message != "" {
message += "\n"
}
@@ -1084,7 +1084,7 @@ func (m *ExplicitMentions) processText(text string, keywords map[string][]string
foundWithoutSuffix := false
wordWithoutSuffix := word
for len(wordWithoutSuffix) > 0 && strings.LastIndexAny(wordWithoutSuffix, ".-:_") == (len(wordWithoutSuffix)-1) {
for wordWithoutSuffix != "" && strings.LastIndexAny(wordWithoutSuffix, ".-:_") == (len(wordWithoutSuffix)-1) {
wordWithoutSuffix = wordWithoutSuffix[0 : len(wordWithoutSuffix)-1]
if m.checkForMention(wordWithoutSuffix, keywords, groups) {

Просмотреть файл

@@ -173,7 +173,7 @@ func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.Author
return "", model.NewAppError("AllowOAuthAppAccessToUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
if len(authRequest.Scope) == 0 {
if authRequest.Scope == "" {
authRequest.Scope = model.DEFAULT_SCOPE
}
@@ -619,7 +619,7 @@ func (a *App) LoginByOAuth(service string, userData io.Reader, teamId string, to
if err = a.UpdateOAuthUserAttrs(bytes.NewReader(buf.Bytes()), user, provider, service, tokenUser); err != nil {
return nil, err
}
if len(teamId) > 0 {
if teamId != "" {
err = a.AddUserToTeamByTeamId(teamId, user)
}
}
@@ -763,11 +763,11 @@ func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, servi
authUrl := endpoint + "?response_type=code&client_id=" + clientId + "&redirect_uri=" + url.QueryEscape(redirectUri) + "&state=" + url.QueryEscape(state)
if len(scope) > 0 {
if scope != "" {
authUrl += "&scope=" + utils.UrlEncode(scope)
}
if len(loginHint) > 0 {
if loginHint != "" {
authUrl += "&login_hint=" + utils.UrlEncode(loginHint)
}
@@ -865,7 +865,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.bad_token.app_error", nil, "token_type="+ar.TokenType+", response_body="+buf.String(), http.StatusInternalServerError)
}
if len(ar.AccessToken) == 0 {
if ar.AccessToken == "" {
return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.missing.app_error", nil, "response_body="+buf.String(), http.StatusInternalServerError)
}

Просмотреть файл

@@ -95,7 +95,7 @@ func (a *App) ExportPermissions(w io.Writer) error {
roles := []*model.Role{}
for _, roleName := range roleNames {
if len(roleName) == 0 {
if roleName == "" {
continue
}
role, err := a.GetRoleByName(roleName)
@@ -206,7 +206,7 @@ func (a *App) ImportPermissions(jsonl io.Reader) error {
{schemeCreated.DefaultChannelGuestRole, schemeIn.DefaultChannelGuestRole},
}
for _, roleNameTuple := range roleNameTuples {
if len(roleNameTuple[0]) == 0 || len(roleNameTuple[1]) == 0 {
if roleNameTuple[0] == "" || roleNameTuple[1] == "" {
continue
}

Просмотреть файл

@@ -654,7 +654,7 @@ func (api *PluginAPI) GetFileLink(fileId string) (string, *model.AppError) {
return "", err
}
if len(info.PostId) == 0 {
if info.PostId == "" {
return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.no_post.app_error", nil, "file_id="+info.Id, http.StatusBadRequest)
}

Просмотреть файл

@@ -1296,21 +1296,21 @@ func TestPluginAPIGetConfig(t *testing.T) {
api := th.SetupPluginAPI()
config := api.GetConfig()
if config.LdapSettings.BindPassword != nil && len(*config.LdapSettings.BindPassword) > 0 {
if config.LdapSettings.BindPassword != nil && *config.LdapSettings.BindPassword != "" {
assert.Equal(t, *config.LdapSettings.BindPassword, model.FAKE_SETTING)
}
assert.Equal(t, *config.FileSettings.PublicLinkSalt, model.FAKE_SETTING)
if len(*config.FileSettings.AmazonS3SecretAccessKey) > 0 {
if *config.FileSettings.AmazonS3SecretAccessKey != "" {
assert.Equal(t, *config.FileSettings.AmazonS3SecretAccessKey, model.FAKE_SETTING)
}
if config.EmailSettings.SMTPPassword != nil && len(*config.EmailSettings.SMTPPassword) > 0 {
if config.EmailSettings.SMTPPassword != nil && *config.EmailSettings.SMTPPassword != "" {
assert.Equal(t, *config.EmailSettings.SMTPPassword, model.FAKE_SETTING)
}
if len(*config.GitLabSettings.Secret) > 0 {
if *config.GitLabSettings.Secret != "" {
assert.Equal(t, *config.GitLabSettings.Secret, model.FAKE_SETTING)
}
@@ -1333,21 +1333,21 @@ func TestPluginAPIGetUnsanitizedConfig(t *testing.T) {
api := th.SetupPluginAPI()
config := api.GetUnsanitizedConfig()
if config.LdapSettings.BindPassword != nil && len(*config.LdapSettings.BindPassword) > 0 {
if config.LdapSettings.BindPassword != nil && *config.LdapSettings.BindPassword != "" {
assert.NotEqual(t, *config.LdapSettings.BindPassword, model.FAKE_SETTING)
}
assert.NotEqual(t, *config.FileSettings.PublicLinkSalt, model.FAKE_SETTING)
if len(*config.FileSettings.AmazonS3SecretAccessKey) > 0 {
if *config.FileSettings.AmazonS3SecretAccessKey != "" {
assert.NotEqual(t, *config.FileSettings.AmazonS3SecretAccessKey, model.FAKE_SETTING)
}
if config.EmailSettings.SMTPPassword != nil && len(*config.EmailSettings.SMTPPassword) > 0 {
if config.EmailSettings.SMTPPassword != nil && *config.EmailSettings.SMTPPassword != "" {
assert.NotEqual(t, *config.EmailSettings.SMTPPassword, model.FAKE_SETTING)
}
if len(*config.GitLabSettings.Secret) > 0 {
if *config.GitLabSettings.Secret != "" {
assert.NotEqual(t, *config.GitLabSettings.Secret, model.FAKE_SETTING)
}

Просмотреть файл

@@ -182,7 +182,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
post.SanitizeProps()
var pchan chan store.StoreResult
if len(post.RootId) > 0 {
if post.RootId != "" {
pchan = make(chan store.StoreResult, 1)
go func() {
r, pErr := a.Srv().Store.Post().Get(post.RootId, false, false, false)
@@ -242,7 +242,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
}
rootPost := parentPostList.Posts[post.RootId]
if len(rootPost.RootId) > 0 {
if rootPost.RootId != "" {
return nil, model.NewAppError("createPost", "api.post.create_post.root_id.app_error", nil, "", http.StatusBadRequest)
}
@@ -439,7 +439,7 @@ func (a *App) FillInPostProps(post *model.Post, channel *model.Channel) *model.A
func (a *App) handlePostEvents(post *model.Post, user *model.User, channel *model.Channel, triggerWebhooks bool, parentPostList *model.PostList, setOnline bool) error {
var team *model.Team
if len(channel.TeamId) > 0 {
if channel.TeamId != "" {
t, err := a.Srv().Store.Team().Get(channel.TeamId)
if err != nil {
return err

Просмотреть файл

@@ -55,7 +55,7 @@ func (s *Server) DoSecurityUpdateCheck() {
v.Set(PropSecurityDatabase, *s.Config().SqlSettings.DriverName)
v.Set(PropSecurityOS, runtime.GOOS)
if len(props[model.SYSTEM_RAN_UNIT_TESTS]) > 0 {
if props[model.SYSTEM_RAN_UNIT_TESTS] != "" {
v.Set(PropSecurityUnitTests, "1")
} else {
v.Set(PropSecurityUnitTests, "0")

Просмотреть файл

@@ -79,7 +79,7 @@ func (*HeaderProvider) DoCommand(a *app.App, args *model.CommandArgs, message st
}
}
if len(message) == 0 {
if message == "" {
return &model.CommandResponse{
Text: args.T("api.command_channel_header.message.app_error"),
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,

Просмотреть файл

@@ -66,7 +66,7 @@ func (*PurposeProvider) DoCommand(a *app.App, args *model.CommandArgs, message s
}
}
if len(message) == 0 {
if message == "" {
return &model.CommandResponse{
Text: args.T("api.command_channel_purpose.message.app_error"),
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,

Просмотреть файл

@@ -66,7 +66,7 @@ func (*RenameProvider) DoCommand(a *app.App, args *model.CommandArgs, message st
return &model.CommandResponse{Text: args.T("api.command_channel_rename.direct_group.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
if len(message) == 0 {
if message == "" {
return &model.CommandResponse{
Text: args.T("api.command_channel_rename.message.app_error"),
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,

Просмотреть файл

@@ -38,7 +38,7 @@ func (*CodeProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Comma
}
func (*CodeProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
if len(message) == 0 {
if message == "" {
return &model.CommandResponse{Text: args.T("api.command_code.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
rmsg := " " + strings.Join(strings.Split(message, "\n"), "\n ")

Просмотреть файл

@@ -43,7 +43,7 @@ func (*EchoProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Comma
}
func (*EchoProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
if len(message) == 0 {
if message == "" {
return &model.CommandResponse{Text: args.T("api.command_echo.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}

Просмотреть файл

@@ -122,7 +122,7 @@ func (*groupmsgProvider) DoCommand(a *app.App, args *model.CommandArgs, message
}
}
if len(parsedMessage) > 0 {
if parsedMessage != "" {
post := &model.Post{}
post.Message = parsedMessage
post.ChannelId = groupChannel.Id

Просмотреть файл

@@ -459,7 +459,7 @@ func (*LoadTestProvider) PostCommand(a *app.App, args *model.CommandArgs, messag
func (*LoadTestProvider) UrlCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
url := strings.TrimSpace(strings.TrimPrefix(message, "url"))
if len(url) == 0 {
if url == "" {
return &model.CommandResponse{Text: "Command must contain a url", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
@@ -513,7 +513,7 @@ func (*LoadTestProvider) UrlCommand(a *app.App, args *model.CommandArgs, message
func (*LoadTestProvider) JsonCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
url := strings.TrimSpace(strings.TrimPrefix(message, "json"))
if len(url) == 0 {
if url == "" {
return &model.CommandResponse{Text: "Command must contain a url", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}

Просмотреть файл

@@ -96,7 +96,7 @@ func (*msgProvider) DoCommand(a *app.App, args *model.CommandArgs, message strin
targetChannelId = channel.Id
}
if len(parsedMessage) > 0 {
if parsedMessage != "" {
post := &model.Post{}
post.Message = parsedMessage
post.ChannelId = targetChannelId

Просмотреть файл

@@ -54,7 +54,7 @@ func (*MuteProvider) DoCommand(a *app.App, args *model.CommandArgs, message stri
channelName = splitMessage[0]
}
if len(channelName) > 0 && len(message) > 0 {
if channelName != "" && message != "" {
channel, _ = a.Srv().Store.Channel().GetByName(channel.TeamId, channelName, true)
if channel == nil {

Просмотреть файл

@@ -96,7 +96,7 @@ func doCommand(a *app.App, args *model.CommandArgs, message string) *model.Comma
}
}
if len(message) == 0 {
if message == "" {
return &model.CommandResponse{
Text: args.T("api.command_remove.message.app_error"),
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,

Просмотреть файл

@@ -37,7 +37,7 @@ func (*ShrugProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Comm
func (*ShrugProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := `¯\\\_(ツ)\_/¯`
if len(message) > 0 {
if message != "" {
rmsg = message + " " + rmsg
}

Просмотреть файл

@@ -39,7 +39,7 @@ func parseSVG(svgReader io.Reader) (SVGInfo, error) {
if viewBoxMatches := viewBoxPattern.FindStringSubmatch(parsedSVG.ViewBox); len(viewBoxMatches) == 5 {
svgInfo.Width, _ = strconv.Atoi(viewBoxMatches[3])
svgInfo.Height, _ = strconv.Atoi(viewBoxMatches[4])
} else if len(parsedSVG.Width) > 0 && len(parsedSVG.Height) > 0 {
} else if parsedSVG.Width != "" && parsedSVG.Height != "" {
widthMatches := dimensionPattern.FindStringSubmatch(parsedSVG.Width)
heightMatches := dimensionPattern.FindStringSubmatch(parsedSVG.Height)
if len(widthMatches) == 2 && len(heightMatches) == 2 {

Просмотреть файл

@@ -1840,7 +1840,7 @@ func (a *App) GetTeamIdFromQuery(query url.Values) (string, *model.AppError) {
tokenId := query.Get("t")
inviteId := query.Get("id")
if len(tokenId) > 0 {
if tokenId != "" {
token, err := a.Srv().Store.Token().GetByToken(tokenId)
if err != nil {
return "", model.NewAppError("GetTeamIdFromQuery", "api.oauth.singup_with_oauth.invalid_link.app_error", nil, "", http.StatusBadRequest)
@@ -1859,7 +1859,7 @@ func (a *App) GetTeamIdFromQuery(query url.Values) (string, *model.AppError) {
return tokenData["teamId"], nil
}
if len(inviteId) > 0 {
if inviteId != "" {
team, err := a.Srv().Store.Team().GetByInviteId(inviteId)
if err == nil {
return team.Id, nil
@@ -1897,7 +1897,7 @@ func (a *App) SanitizeTeams(session model.Session, teams []*model.Team) []*model
}
func (a *App) GetTeamIcon(team *model.Team) ([]byte, *model.AppError) {
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return nil, model.NewAppError("GetTeamIcon", "api.team.get_team_icon.filesettings_no_driver.app_error", nil, "", http.StatusNotImplemented)
}
@@ -1926,7 +1926,7 @@ func (a *App) SetTeamIconFromMultiPartFile(teamId string, file multipart.File) *
return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.get_team.app_error", nil, getTeamErr.Error(), http.StatusBadRequest)
}
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
return model.NewAppError("setTeamIcon", "api.team.set_team_icon.storage.app_error", nil, "", http.StatusNotImplemented)
}

Просмотреть файл

@@ -393,7 +393,7 @@ func (a *App) CreateOAuthUser(service string, userData io.Reader, teamId string,
return nil, err
}
if len(teamId) > 0 {
if teamId != "" {
err = a.AddUserToTeamByTeamId(teamId, user)
if err != nil {
return nil, err
@@ -410,7 +410,7 @@ func (a *App) CreateOAuthUser(service string, userData io.Reader, teamId string,
// CheckEmailDomain checks that an email domain matches a list of space-delimited domains as a string.
func CheckEmailDomain(email string, domains string) bool {
if len(domains) == 0 {
if domains == "" {
return true
}
@@ -762,7 +762,7 @@ func (a *App) ActivateMfa(userId, token string) *model.AppError {
}
}
if len(user.AuthService) > 0 && user.AuthService != model.USER_AUTH_SERVICE_LDAP {
if user.AuthService != "" && user.AuthService != model.USER_AUTH_SERVICE_LDAP {
return model.NewAppError("ActivateMfa", "api.user.activate_mfa.email_and_ldap_only.app_error", nil, "", http.StatusBadRequest)
}
@@ -873,7 +873,7 @@ func getFont(initialFont string) (*truetype.Font, error) {
}
func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError) {
if len(*a.Config().FileSettings.DriverName) == 0 {
if *a.Config().FileSettings.DriverName == "" {
img, appErr := a.GetDefaultProfileImage(user)
if appErr != nil {
return nil, false, appErr

Просмотреть файл

@@ -435,7 +435,7 @@ func (h *Hub) Start() {
connIndex.Remove(webConn)
atomic.StoreInt64(&h.connectionCount, int64(len(connIndex.All())))
if len(webConn.UserId) == 0 {
if webConn.UserId == "" {
continue
}

Просмотреть файл

@@ -51,7 +51,7 @@ func (a *App) handleWebhookEvents(post *model.Post, team *model.Team, channel *m
relevantHooks := []*model.OutgoingWebhook{}
for _, hook := range hooks {
if hook.ChannelId == post.ChannelId || len(hook.ChannelId) == 0 {
if hook.ChannelId == post.ChannelId || hook.ChannelId == "" {
if hook.ChannelId == post.ChannelId && len(hook.TriggerWords) == 0 {
relevantHooks = append(relevantHooks, hook)
triggerWord = ""
@@ -503,7 +503,7 @@ func (a *App) UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook)
return nil, model.NewAppError("UpdateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
if len(updatedHook.ChannelId) > 0 {
if updatedHook.ChannelId != "" {
channel, err := a.GetChannel(updatedHook.ChannelId)
if err != nil {
return nil, err
@@ -658,7 +658,7 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
}
text := req.Text
if len(text) == 0 && req.Attachments == nil {
if text == "" && req.Attachments == nil {
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.text.app_error", nil, "", http.StatusBadRequest)
}