Skip to content

Commit

Permalink
Release v0.18.2 - Cherry picks (#515)
Browse files Browse the repository at this point in the history
* MM-54259 - Fix: Panic in isMobilePostGA (#505)

* remove isMobilePostGA code

* Revert "remove isMobilePostGA code"

This reverts commit 0ab4977.

* fix the crash

* MM-54313 - Fix: panic in handleGetAllChannels (#511)

* fix MM-54313

* wrap appErr
  • Loading branch information
cpoile authored Sep 1, 2023
1 parent 5c059da commit a29ebe0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions server/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a29ebe0

Please sign in to comment.