From f86c8255bb19a120fb4cf1e7a8c7ea51ffa29552 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 10 Sep 2013 17:13:02 -0400 Subject: [PATCH] Safety check for stream_data:[add|remove]_subscriber Though this should not be common, getting a peer subscribed/ unsubscribed notification to a stream we don't yet know about should not be fatal (imported from commit ee28b163e0efc9adfad31e1b321e986dfe56271e) --- static/js/stream_data.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/static/js/stream_data.js b/static/js/stream_data.js index 23299dbcda..a93c814f5b 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -101,9 +101,10 @@ exports.get_name = function (stream_name) { exports.add_subscriber = function (stream_name, user_email) { var sub = exports.get_sub(stream_name); - if (!sub.subscribed) { + if (typeof sub === 'undefined' || !sub.subscribed) { // If we're not subscribed, we don't track this, and shouldn't - // get these events. + // get these events. Likewise, if we don't know about the stream, + // we don't want to track this. return; } sub.subscribers.set(user_email, true); @@ -111,9 +112,10 @@ exports.add_subscriber = function (stream_name, user_email) { exports.remove_subscriber = function (stream_name, user_email) { var sub = exports.get_sub(stream_name); - if (!sub.subscribed) { + if (typeof sub === 'undefined' || !sub.subscribed) { // If we're not subscribed, we don't track this, and shouldn't - // get these events. + // get these events. Likewise, if we don't know about the stream, + // we don't want to track this. return; } sub.subscribers.del(user_email);