Skip to content

Commit

Permalink
MM-54259 - Fix: Panic in isMobilePostGA (#505)
Browse files Browse the repository at this point in the history
* remove isMobilePostGA code

* Revert "remove isMobilePostGA code"

This reverts commit 0ab4977.

* fix the crash
  • Loading branch information
cpoile committed Aug 29, 2023
1 parent 5c059da commit 5166bf5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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 5166bf5

Please sign in to comment.