From a29ebe0ca2fc9ee645d6b8bbbf10132db2bcfad8 Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Fri, 1 Sep 2023 12:28:25 -0400 Subject: [PATCH] Release v0.18.2 - Cherry picks (#515) * MM-54259 - Fix: Panic in isMobilePostGA (#505) * remove isMobilePostGA code * Revert "remove isMobilePostGA code" This reverts commit 0ab4977e4472964e8c7470a8628e0fd3acef9ce9. * fix the crash * MM-54313 - Fix: panic in handleGetAllChannels (#511) * fix MM-54313 * wrap appErr --- server/api.go | 2 +- server/utils.go | 6 +++++- server/utils_test.go | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/server/api.go b/server/api.go index 39641e726..3f1d7b27e 100644 --- a/server/api.go +++ b/server/api.go @@ -139,7 +139,7 @@ func (p *Plugin) handleGetAllChannels(w http.ResponseWriter, r *http.Request) { state, err := p.kvGetChannelState(channelID) if err != nil { p.LogError(err.Error()) - http.Error(w, appErr.Error(), http.StatusInternalServerError) + continue } enabled := state.Enabled diff --git a/server/utils.go b/server/utils.go index f3370eda4..21abc1931 100644 --- a/server/utils.go +++ b/server/utils.go @@ -113,7 +113,11 @@ func isMobilePostGA(r *http.Request) (mobile, postGA bool) { // https://mattermost.atlassian.net/browse/MM-48929 userAgent := r.Header.Get("User-Agent") fields := strings.Fields(userAgent) - clientAgent := fields[0] // safe to assume there's at least one + if len(fields) == 0 { + return false, false + } + + clientAgent := fields[0] isMobile := strings.HasPrefix(clientAgent, "rnbeta") || strings.HasPrefix(clientAgent, "Mattermost") if !isMobile { return false, false diff --git a/server/utils_test.go b/server/utils_test.go index bd54afbe1..c2d71178d 100644 --- a/server/utils_test.go +++ b/server/utils_test.go @@ -47,6 +47,13 @@ func Test_isMobilePostGA(t *testing.T) { wantMobile: true, wantPostGA: true, }, + { + name: "no user agent", + userAgent: "", + params: "", + wantMobile: false, + wantPostGA: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {