[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)').
This commit is contained in:
Aaron Bohy
2015-10-02 15:49:37 +02:00
parent 28d3dc6cc9
commit de8acb2569
+3 -3
View File
@@ -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|$|</[a-z]*>)");
_.each(_.keys(emoji_substitutions), function (key) {
var escaped_key = String(key).replace(/([.*+?=^!:${}()|[\]\/\\])/g, '\\$1');
var regexp = new RegExp("(?:^|\\s|<[a-z]*>)(" + escaped_key + ")(?=\\s|$|</[a-z]*>)", "g");
msg.body = msg.body.replace(regexp, ' <span class="o_mail_emoji">'+emoji_substitutions[key]+'</span> ');
});