Fix empty string comparison issues in the codebase (#16686)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
200a56fa5a
Коммит
94c24eea20
@@ -74,7 +74,7 @@ func (c *Context) LogAudit(extraInfo string) {
|
||||
|
||||
func (c *Context) LogAuditWithUserId(userId, extraInfo string) {
|
||||
|
||||
if len(c.App.Session().UserId) > 0 {
|
||||
if c.App.Session().UserId != "" {
|
||||
extraInfo = strings.TrimSpace(extraInfo + " session_user=" + c.App.Session().UserId)
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (c *Context) SessionRequired() {
|
||||
return
|
||||
}
|
||||
|
||||
if len(c.App.Session().UserId) == 0 {
|
||||
if c.App.Session().UserId == "" {
|
||||
c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "UserRequired", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
@@ -214,7 +214,7 @@ func (c *Context) SetCommandNotFoundError() {
|
||||
|
||||
func (c *Context) HandleEtag(etag string, routeName string, w http.ResponseWriter, r *http.Request) bool {
|
||||
metrics := c.App.Metrics()
|
||||
if et := r.Header.Get(model.HEADER_ETAG_CLIENT); len(etag) > 0 {
|
||||
if et := r.Header.Get(model.HEADER_ETAG_CLIENT); etag != "" {
|
||||
if et == etag {
|
||||
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
|
||||
w.WriteHeader(http.StatusNotModified)
|
||||
@@ -299,7 +299,7 @@ func (c *Context) RequireInviteId() *Context {
|
||||
return c
|
||||
}
|
||||
|
||||
if len(c.Params.InviteId) == 0 {
|
||||
if c.Params.InviteId == "" {
|
||||
c.SetInvalidUrlParam("invite_id")
|
||||
}
|
||||
return c
|
||||
@@ -412,7 +412,7 @@ func (c *Context) RequireFilename() *Context {
|
||||
return c
|
||||
}
|
||||
|
||||
if len(c.Params.Filename) == 0 {
|
||||
if c.Params.Filename == "" {
|
||||
c.SetInvalidUrlParam("filename")
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ func (c *Context) RequirePluginId() *Context {
|
||||
return c
|
||||
}
|
||||
|
||||
if len(c.Params.PluginId) == 0 {
|
||||
if c.Params.PluginId == "" {
|
||||
c.SetInvalidUrlParam("plugin_id")
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ func (c *Context) RequireService() *Context {
|
||||
return c
|
||||
}
|
||||
|
||||
if len(c.Params.Service) == 0 {
|
||||
if c.Params.Service == "" {
|
||||
c.SetInvalidUrlParam("service")
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ func (c *Context) RequireEmojiName() *Context {
|
||||
|
||||
validName := regexp.MustCompile(`^[a-zA-Z0-9\-\+_]+$`)
|
||||
|
||||
if len(c.Params.EmojiName) == 0 || len(c.Params.EmojiName) > model.EMOJI_NAME_MAX_LENGTH || !validName.MatchString(c.Params.EmojiName) {
|
||||
if c.Params.EmojiName == "" || len(c.Params.EmojiName) > model.EMOJI_NAME_MAX_LENGTH || !validName.MatchString(c.Params.EmojiName) {
|
||||
c.SetInvalidUrlParam("emoji_name")
|
||||
}
|
||||
|
||||
@@ -578,7 +578,7 @@ func (c *Context) RequireJobType() *Context {
|
||||
return c
|
||||
}
|
||||
|
||||
if len(c.Params.JobType) == 0 || len(c.Params.JobType) > 32 {
|
||||
if c.Params.JobType == "" || len(c.Params.JobType) > 32 {
|
||||
c.SetInvalidUrlParam("job_type")
|
||||
}
|
||||
return c
|
||||
@@ -634,7 +634,7 @@ func (c *Context) RequireRemoteId() *Context {
|
||||
return c
|
||||
}
|
||||
|
||||
if len(c.Params.RemoteId) == 0 {
|
||||
if c.Params.RemoteId == "" {
|
||||
c.SetInvalidUrlParam("remote_id")
|
||||
}
|
||||
return c
|
||||
|
||||
@@ -284,7 +284,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
c.Err.IsOAuth = false
|
||||
}
|
||||
|
||||
if IsApiCall(c.App, r) || IsWebhookCall(c.App, r) || IsOAuthApiCall(c.App, r) || len(r.Header.Get("X-Mobile-App")) > 0 {
|
||||
if IsApiCall(c.App, r) || IsWebhookCall(c.App, r) || IsOAuthApiCall(c.App, r) || r.Header.Get("X-Mobile-App") != "" {
|
||||
w.WriteHeader(c.Err.StatusCode)
|
||||
w.Write([]byte(c.Err.ToJson()))
|
||||
} else {
|
||||
|
||||
10
web/oauth.go
10
web/oauth.go
@@ -133,7 +133,7 @@ func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// here we should check if the user is logged in
|
||||
if len(c.App.Session().UserId) == 0 {
|
||||
if c.App.Session().UserId == "" {
|
||||
if loginHint == model.USER_AUTH_SERVICE_SAML {
|
||||
http.Redirect(w, r, c.GetSiteURLHeader()+"/login/sso/saml?redirect_to="+url.QueryEscape(r.RequestURI), http.StatusFound)
|
||||
} else {
|
||||
@@ -190,12 +190,12 @@ func getAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
grantType := r.FormValue("grant_type")
|
||||
switch grantType {
|
||||
case model.ACCESS_TOKEN_GRANT_TYPE:
|
||||
if len(code) == 0 {
|
||||
if code == "" {
|
||||
c.Err = model.NewAppError("getAccessToken", "api.oauth.get_access_token.missing_code.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
case model.REFRESH_TOKEN_GRANT_TYPE:
|
||||
if len(refreshToken) == 0 {
|
||||
if refreshToken == "" {
|
||||
c.Err = model.NewAppError("getAccessToken", "api.oauth.get_access_token.missing_refresh_token.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func getAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
secret := r.FormValue("client_secret")
|
||||
if len(secret) == 0 {
|
||||
if secret == "" {
|
||||
c.Err = model.NewAppError("getAccessToken", "api.oauth.get_access_token.bad_client_secret.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -258,7 +258,7 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
code := r.URL.Query().Get("code")
|
||||
if len(code) == 0 {
|
||||
if code == "" {
|
||||
utils.RenderWebError(c.App.Config(), w, r, http.StatusTemporaryRedirect, url.Values{
|
||||
"type": []string{"oauth_missing_code"},
|
||||
"service": []string{strings.Title(service)},
|
||||
|
||||
@@ -91,13 +91,13 @@ func TestAuthorizeOAuthApp(t *testing.T) {
|
||||
authRequest.ResponseType = model.IMPLICIT_RESPONSE_TYPE
|
||||
ruri, resp = ApiClient.AuthorizeOAuthApp(authRequest)
|
||||
require.Nil(t, resp.Error)
|
||||
require.False(t, len(ruri) == 0, "redirect url should be set")
|
||||
require.False(t, ruri == "", "redirect url should be set")
|
||||
|
||||
ru, _ = url.Parse(ruri)
|
||||
require.NotNil(t, ru, "redirect url unparseable")
|
||||
values, err := url.ParseQuery(ru.Fragment)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, len(values.Get("access_token")) == 0, "access_token not returned")
|
||||
assert.False(t, values.Get("access_token") == "", "access_token not returned")
|
||||
assert.Equal(t, authRequest.State, values.Get("state"), "returned state doesn't match")
|
||||
|
||||
oldToken := ApiClient.AuthToken
|
||||
@@ -526,7 +526,7 @@ func HttpGet(url string, httpClient *http.Client, authToken string, followRedire
|
||||
rq, _ := http.NewRequest("GET", url, nil)
|
||||
rq.Close = true
|
||||
|
||||
if len(authToken) > 0 {
|
||||
if authToken != "" {
|
||||
rq.Header.Set(model.HEADER_AUTH, authToken)
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
relayState := r.FormValue("RelayState")
|
||||
|
||||
relayProps := make(map[string]string)
|
||||
if len(relayState) > 0 {
|
||||
if relayState != "" {
|
||||
stateStr := ""
|
||||
b, err := b64.StdEncoding.DecodeString(relayState)
|
||||
if err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user