From fd994fdd97066d57e3e550d12e082e422ddec708 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 23 Oct 2015 01:59:31 +0200 Subject: [PATCH] Fixed encodeEntities Also fixed nested emojis in links Closes #702 --- app/js/lib/ng_utils.js | 3 ++- app/js/lib/utils.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/js/lib/ng_utils.js b/app/js/lib/ng_utils.js index 96c737dc..49702af0 100644 --- a/app/js/lib/ng_utils.js +++ b/app/js/lib/ng_utils.js @@ -1425,6 +1425,7 @@ angular.module('izhukov.utils', []) if (nested === undefined) { return encodeEntities(text); } + options.hasNested = true; return wrapRichText(text, {entities: nested, nested: true}); } @@ -1642,7 +1643,7 @@ angular.module('izhukov.utils', []) text = $sanitize(html.join('')); - if (emojiFound && !options.nested) { + if (!options.nested && (emojiFound || options.hasNested)) { text = text.replace(/\ufe0f|️|�|‍/g, '', text); text = text.replace(//g, ''); diff --git a/app/js/lib/utils.js b/app/js/lib/utils.js index 347f81d8..932a5af5 100644 --- a/app/js/lib/utils.js +++ b/app/js/lib/utils.js @@ -361,6 +361,11 @@ function templateUrl (tplName) { function encodeEntities(value) { return value. replace(/&/g, '&'). + replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, function (value) { + var hi = value.charCodeAt(0); + var low = value.charCodeAt(1); + return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';'; + }). replace(/([^\#-~| |!])/g, function (value) { // non-alphanumeric return '&#' + value.charCodeAt(0) + ';'; }).