From 4a03dcab2031a31eb60f99b6d15a70ff0449182c Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 18 Feb 2016 13:49:09 +0000 Subject: [PATCH] Fix problem with double-byte Unicode entities Entities such as `👷` were broken because `String.fromCharCode()` is not fully Unicode aware. The fix is to use `String.fromCodePoint()` where available. Noted by @ericshulman --- core/modules/utils/utils.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index 90015609d..08aac62fd 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -383,17 +383,18 @@ exports.htmlEncode = function(s) { // Converts all HTML entities to their character equivalents exports.entityDecode = function(s) { - var e = s.substr(1,s.length-2); // Strip the & and the ; + var converter = String.fromCodePoint || String.fromCharCode; + e = s.substr(1,s.length-2); // Strip the & and the ; if(e.charAt(0) === "#") { if(e.charAt(1) === "x" || e.charAt(1) === "X") { - return String.fromCharCode(parseInt(e.substr(2),16)); + return converter(parseInt(e.substr(2),16)); } else { - return String.fromCharCode(parseInt(e.substr(1),10)); + return converter(parseInt(e.substr(1),10)); } } else { var c = $tw.config.htmlEntities[e]; if(c) { - return String.fromCharCode(c); + return converter(c); } else { return s; // Couldn't convert it as an entity, just return it raw }