From ec8e1cca157c250534483accad62d82a174cf1c2 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 30 Jul 2018 08:56:51 -0400 Subject: [PATCH] fix https://github.com/uBlockOrigin/uBlock-issues/issues/149 --- src/js/i18n.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/js/i18n.js b/src/js/i18n.js index d10be88d8..cdd0bb48e 100644 --- a/src/js/i18n.js +++ b/src/js/i18n.js @@ -79,16 +79,27 @@ var safeTextToTagNode = function(text) { } }; -var safeTextToTextNode = function(text) { - // TODO: remove once no more HTML entities in translation files. - if ( text.indexOf('&') !== -1 ) { - text = text.replace(/“/g, '“') - .replace(/”/g, '”') - .replace(/‘/g, '‘') - .replace(/’/g, '’'); - } - return document.createTextNode(text); -}; +var safeTextToTextNode = (function() { + let entities = new Map([ + // TODO: Remove quote entities once no longer present in translation + // files. Other entities must stay. + [ '“', '“' ], + [ '”', '”' ], + [ '‘', '‘' ], + [ '’', '’' ], + [ '<', '<' ], + [ '>', '>' ], + ]); + let decodeEntities = match => { + return entities.get(match) || match; + }; + return function(text) { + if ( text.indexOf('&') !== -1 ) { + text = text.replace(/&[a-z]+;/g, decodeEntities); + } + return document.createTextNode(text); + }; +})(); var safeTextToDOM = function(text, parent) { if ( text === '' ) { return; }