From e739a91c94049aa62cfe76b9c6686fb18184232b Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 3 Mar 2017 12:25:32 -0500 Subject: Fix JS error when receiving reply during channel switch (#5582) --- api/channel.go | 4 ++++ api/channel_test.go | 5 ++++- api4/channel_test.go | 11 +++++++++++ webapp/stores/post_store.jsx | 6 +++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/api/channel.go b/api/channel.go index 2604cc5ce..9c11f073e 100644 --- a/api/channel.go +++ b/api/channel.go @@ -772,6 +772,10 @@ func autocompleteChannels(c *Context, w http.ResponseWriter, r *http.Request) { func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) { view := model.ChannelViewFromJson(r.Body) + if view == nil { + c.SetInvalidParam("viewChannel", "channel_view") + return + } if err := app.ViewChannel(view, c.Session.UserId, !c.Session.IsMobileApp()); err != nil { c.Err = err diff --git a/api/channel_test.go b/api/channel_test.go index d8da3374b..93c79d416 100644 --- a/api/channel_test.go +++ b/api/channel_test.go @@ -903,7 +903,6 @@ func TestGetChannel(t *testing.T) { if _, err := Client.GetChannels(""); err == nil { t.Fatal("should have failed - wrong team id") } - } func TestGetMoreChannelsPage(t *testing.T) { @@ -2003,6 +2002,10 @@ func TestViewChannel(t *testing.T) { t.Log(rdata.Member.MsgCount) t.Fatal("message counts don't match") } + + if _, err := Client.DoApiPost(Client.GetTeamRoute()+"/channels/view", "garbage"); err == nil { + t.Fatal("should have been an error") + } } func TestGetChannelMembersByIds(t *testing.T) { diff --git a/api4/channel_test.go b/api4/channel_test.go index 7dcc8dc96..c8faf7aa1 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -4,6 +4,7 @@ package api4 import ( + "fmt" "net/http" "strconv" "testing" @@ -504,6 +505,16 @@ func TestViewChannel(t *testing.T) { _, resp = Client.ViewChannel(th.BasicUser2.Id, view) CheckForbiddenStatus(t, resp) + if r, err := Client.DoApiPost(fmt.Sprintf("/channels/members/%v/view", th.BasicUser.Id), "garbage"); err == nil { + t.Fatal("should have errored") + } else { + if r.StatusCode != http.StatusBadRequest { + t.Log("actual: " + strconv.Itoa(r.StatusCode)) + t.Log("expected: " + strconv.Itoa(http.StatusBadRequest)) + t.Fatal("wrong status code") + } + } + Client.Logout() _, resp = Client.ViewChannel(th.BasicUser.Id, view) CheckUnauthorizedStatus(t, resp) diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx index 360b7cd72..6e312f67a 100644 --- a/webapp/stores/post_store.jsx +++ b/webapp/stores/post_store.jsx @@ -99,11 +99,11 @@ class PostStoreClass extends EventEmitter { return null; } - const posts = postInfo.postList; + const postList = postInfo.postList; let post = null; - if (posts.posts.hasOwnProperty(postId)) { - post = posts.posts[postId]; + if (postList && postList.posts && postList.posts.hasOwnProperty(postId)) { + post = postList.posts[postId]; } return post; -- cgit v1.2.3-1-g7c22