Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

reactions: Handle missing realm emojis.

Steve Howell98529564aed4
diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js
index d078a7b54cd..fc7627001e7 100644
--- a/frontend_tests/node_tests/reactions.js
+++ b/frontend_tests/node_tests/reactions.js
@@ -179,6 +179,24 @@ run_test("basics", () => {
assert.deepEqual(result, expected_result);
});
+run_test("unknown realm emojis (add)", () => {
+ blueslip.expect("error", "Cannot find/add realm emoji for code 'broken'.");
+ reactions.add_clean_reaction({
+ reaction_type: "realm_emoji",
+ emoji_code: "broken",
+ user_ids: [alice.user_id],
+ });
+});
+
+run_test("unknown realm emojis (insert)", () => {
+ blueslip.expect("error", "Cannot find/insert realm emoji for code 'bogus'.");
+ reactions.view.insert_new_reaction({
+ reaction_type: "realm_emoji",
+ emoji_code: "bogus",
+ user_id: bob.user_id,
+ });
+});
+
run_test("sending", (override) => {
const message_id = 1001; // see above for setup
let emoji_name = "smile"; // should be a current reaction
diff --git a/static/js/reactions.js b/static/js/reactions.js
index bdf7ac810f1..542c85d0f29 100644
--- a/static/js/reactions.js
+++ b/static/js/reactions.js
@@ -295,7 +295,12 @@ exports.view.insert_new_reaction = function (opts) {
if (opts.reaction_type !== "unicode_emoji") {
context.is_realm_emoji = true;
- context.url = emoji.all_realm_emojis.get(emoji_code).emoji_url;
+ const emoji_info = emoji.all_realm_emojis.get(emoji_code);
+ if (!emoji_info) {
+ blueslip.error(`Cannot find/insert realm emoji for code '${emoji_code}'.`);
+ return;
+ }
+ context.url = emoji_info.emoji_url;
}
context.count = 1;
@@ -499,7 +504,12 @@ exports.add_clean_reaction = function (opts) {
if (r.reaction_type !== "unicode_emoji") {
r.is_realm_emoji = true;
- r.url = emoji.all_realm_emojis.get(r.emoji_code).emoji_url;
+ const emoji_info = emoji.all_realm_emojis.get(r.emoji_code);
+ if (!emoji_info) {
+ blueslip.error(`Cannot find/add realm emoji for code '${r.emoji_code}'.`);
+ return;
+ }
+ r.url = emoji_info.emoji_url;
}
opts.message.clean_reactions.set(opts.local_id, r);