From de8acb2569fd1b93d9e9c62ecc2ede79064037f8 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 2 Oct 2015 12:25:52 +0200 Subject: [PATCH] [FIX] mail: emojis: replace all occurences of the emoji in messages The problem was that, when substituting the emoji pattern by the emoji icon, we only replaced the first occurence of the pattern. This rev. replaces all occurences of the pattern by performing a global match ('g' option), and correctly handles matches overlap by using a lookahead assertion ('x(?=y)') instead of basic non-capturing parentheses ('x(?:y)'). --- addons/mail/static/src/js/chat_manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 240355f79d4..df57cc8bbfa 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -75,9 +75,9 @@ function make_message (data, channel_id) { res_id: data.res_id, }; - _.each(_.keys(emoji_substitutions), function(key){ - var escaped_key = String(key).replace(/([.*+?=^!:${}()|[\]\/\\])/g, '\\$1'); //] - var regexp = new RegExp("(?:^|\\s|<[a-z]*>)(" + escaped_key + ")(?:\\s|$|)"); + _.each(_.keys(emoji_substitutions), function (key) { + var escaped_key = String(key).replace(/([.*+?=^!:${}()|[\]\/\\])/g, '\\$1'); + var regexp = new RegExp("(?:^|\\s|<[a-z]*>)(" + escaped_key + ")(?=\\s|$|)", "g"); msg.body = msg.body.replace(regexp, ' '+emoji_substitutions[key]+' '); });