From 27f37e6378f32985b1cbb9ae6ddb4c718dc33d74 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sat, 18 Mar 2017 10:29:20 -0700 Subject: [PATCH] Add hash_util.encodeHashComponent() shim. --- .eslintrc.json | 1 + frontend_tests/node_tests/activity.js | 4 ++++ frontend_tests/node_tests/echo.js | 5 +++++ frontend_tests/node_tests/hashchange.js | 5 +++++ frontend_tests/node_tests/narrow.js | 4 ++++ frontend_tests/node_tests/pm_list.js | 4 ++++ frontend_tests/node_tests/stream_data.js | 4 ++++ frontend_tests/node_tests/stream_list.js | 5 +++++ frontend_tests/node_tests/topic_list.js | 4 ++++ static/js/click_handlers.js | 2 +- static/js/echo.js | 2 +- static/js/hashchange.js | 2 +- static/js/narrow.js | 20 ++++++++++---------- static/js/shim.js | 3 +++ static/js/subs.js | 2 +- 15 files changed, 53 insertions(+), 14 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index eaeead79ae..8d2b100c1d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -48,6 +48,7 @@ "topic_list": false, "gear_menu": false, "hashchange": false, + "hash_util": false, "message_list": false, "Filter": false, "pointer": false, diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index 0ed8a3f595..098b217c67 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -28,6 +28,10 @@ set_global('resize', { resize_page_components: function () {}, }); +set_global('hash_util', { + encodeHashComponent: global.hashchange.encodeHashComponent, +}); + var me = { email: 'me@zulip.com', user_id: 999, diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js index a199a6e320..3e76ff66e2 100644 --- a/frontend_tests/node_tests/echo.js +++ b/frontend_tests/node_tests/echo.js @@ -54,6 +54,11 @@ set_global('$', function (obj) { set_global('feature_flags', {local_echo: true}); +set_global('hash_util', { + encodeHashComponent: global.hashchange.encodeHashComponent, +}); + + jsdom.changeURL(window, 'http://zulip.zulipdev.com'); set_global('window', window); diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js index 0b9522ad60..92f003bbcf 100644 --- a/frontend_tests/node_tests/hashchange.js +++ b/frontend_tests/node_tests/hashchange.js @@ -6,6 +6,11 @@ add_dependencies({ var hashchange = require('js/hashchange.js'); +set_global('hash_util', { + encodeHashComponent: hashchange.encodeHashComponent, +}); + + (function test_operators_round_trip() { var operators; var hash; diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.js index 86e802d86f..462a3369ce 100644 --- a/frontend_tests/node_tests/narrow.js +++ b/frontend_tests/node_tests/narrow.js @@ -12,6 +12,10 @@ var Filter = global.Filter; var stream_data = global.stream_data; var _ = global._; +set_global('hash_util', { + encodeHashComponent: global.hashchange.encodeHashComponent, +}); + function set_filter(operators) { operators = _.map(operators, function (op) { return {operator: op[0], operand: op[1]}; diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js index 2c5eede553..839395950d 100644 --- a/frontend_tests/node_tests/pm_list.js +++ b/frontend_tests/node_tests/pm_list.js @@ -14,6 +14,10 @@ set_global('message_store', { set_global('unread', {}); +set_global('hash_util', { + encodeHashComponent: global.hashchange.encodeHashComponent, +}); + // TODO: move pm_list-related tests to their own module var pm_list = require('js/pm_list.js'); diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index a3143f1ce0..429290406e 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -15,6 +15,10 @@ add_dependencies({ set_global('blueslip', {}); +set_global('hash_util', { + encodeHashComponent: global.hashchange.encodeHashComponent, +}); + var stream_data = require('js/stream_data.js'); var people = global.people; diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index 4248173826..40ff76e6e2 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -16,6 +16,11 @@ add_dependencies({ var stream_list = require('js/stream_list.js'); +set_global('hash_util', { + encodeHashComponent: global.hashchange.encodeHashComponent, +}); + + var jsdom = require("jsdom"); var window = jsdom.jsdom().defaultView; global.$ = require('jquery')(window); diff --git a/frontend_tests/node_tests/topic_list.js b/frontend_tests/node_tests/topic_list.js index fa9761cbe5..c29c44e3c2 100644 --- a/frontend_tests/node_tests/topic_list.js +++ b/frontend_tests/node_tests/topic_list.js @@ -15,6 +15,10 @@ global.$ = require('jquery')(window); var topic_list = require('js/topic_list.js'); +set_global('hash_util', { + encodeHashComponent: global.hashchange.encodeHashComponent, +}); + global.compile_template('topic_list_item'); (function test_topic_list_build_widget() { diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js index 6075cd4677..21dc22fc8f 100644 --- a/static/js/click_handlers.js +++ b/static/js/click_handlers.js @@ -92,7 +92,7 @@ $(function () { e.preventDefault(); var stream = stream_data.get_sub_by_id($(this).attr('data-stream-id')); if (stream) { - window.location.href = '/#narrow/stream/' + hashchange.encodeHashComponent(stream.name); + window.location.href = '/#narrow/stream/' + hash_util.encodeHashComponent(stream.name); return; } window.location.href = $(this).attr('href'); diff --git a/static/js/echo.js b/static/js/echo.js index 1a5f84debe..50f4ae4664 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -352,7 +352,7 @@ function handleStream(streamName) { } return '' + '#' + stream.name + ''; } diff --git a/static/js/hashchange.js b/static/js/hashchange.js index 66ed913364..957784092f 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -88,7 +88,7 @@ exports.operators_to_hash = function (operators) { var operand = elem.operand; var sign = elem.negated ? '-' : ''; - hash += '/' + sign + hashchange.encodeHashComponent(operator) + hash += '/' + sign + hash_util.encodeHashComponent(operator) + '/' + hashchange.encode_operand(operator, operand); }); } diff --git a/static/js/narrow.js b/static/js/narrow.js index 272f283029..4db48ac932 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -614,30 +614,30 @@ exports.by_sender_uri = function (reply_to) { }; exports.by_stream_uri = function (stream) { - return "#narrow/stream/" + hashchange.encodeHashComponent(stream); + return "#narrow/stream/" + hash_util.encodeHashComponent(stream); }; exports.by_stream_subject_uri = function (stream, subject) { - return "#narrow/stream/" + hashchange.encodeHashComponent(stream) + - "/subject/" + hashchange.encodeHashComponent(subject); + return "#narrow/stream/" + hash_util.encodeHashComponent(stream) + + "/subject/" + hash_util.encodeHashComponent(subject); }; exports.by_message_uri = function (message_id) { - return "#narrow/id/" + hashchange.encodeHashComponent(message_id); + return "#narrow/id/" + hash_util.encodeHashComponent(message_id); }; exports.by_near_uri = function (message_id) { - return "#narrow/near/" + hashchange.encodeHashComponent(message_id); + return "#narrow/near/" + hash_util.encodeHashComponent(message_id); }; exports.by_conversation_and_time_uri = function (message) { if (message.type === "stream") { - return "#narrow/stream/" + hashchange.encodeHashComponent(message.stream) + - "/subject/" + hashchange.encodeHashComponent(message.subject) + - "/near/" + hashchange.encodeHashComponent(message.id); + return "#narrow/stream/" + hash_util.encodeHashComponent(message.stream) + + "/subject/" + hash_util.encodeHashComponent(message.subject) + + "/near/" + hash_util.encodeHashComponent(message.id); } - return "#narrow/pm-with/" + hashchange.encodeHashComponent(message.reply_to) + - "/near/" + hashchange.encodeHashComponent(message.id); + return "#narrow/pm-with/" + hash_util.encodeHashComponent(message.reply_to) + + "/near/" + hash_util.encodeHashComponent(message.id); }; // Are we narrowed to PMs: all PMs or PMs with particular people. diff --git a/static/js/shim.js b/static/js/shim.js index e9e76dd40e..29fae476ba 100644 --- a/static/js/shim.js +++ b/static/js/shim.js @@ -13,5 +13,8 @@ var compose_actions = {}; compose_actions.start = compose.start; compose_actions.cancel = compose.cancel; +var hash_util = {}; +hash_util.encodeHashComponent = hashchange.encodeHashComponent; + var compose_state = {}; compose_state.has_message_content = compose.has_message_content; diff --git a/static/js/subs.js b/static/js/subs.js index 799118ccd9..7146d0180d 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -1423,7 +1423,7 @@ $(function () { window.location.hash = "#streams" + "/" + stream_id + "/" + - hashchange.encodeHashComponent(sub.name); + hash_util.encodeHashComponent(sub.name); } });