From a974562f7e8ef897465bc1b9e7a9a66d8896bbca Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 27 May 2020 06:54:11 -0400 Subject: [PATCH] Expand HTML entities in `title` attribute Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1074 --- src/js/i18n.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/js/i18n.js b/src/js/i18n.js index 12ad65130..3aa1719d4 100644 --- a/src/js/i18n.js +++ b/src/js/i18n.js @@ -69,7 +69,7 @@ const safeTextToTagNode = function(text) { } }; -const safeTextToTextNode = (function() { +const expandHtmlEntities = (( ) => { const entities = new Map([ // TODO: Remove quote entities once no longer present in translation // files. Other entities must stay. @@ -88,10 +88,14 @@ const safeTextToTextNode = (function() { if ( text.indexOf('&') !== -1 ) { text = text.replace(/&[a-z]+;/g, decodeEntities); } - return document.createTextNode(text); + return text; }; })(); +const safeTextToTextNode = function(text) { + return document.createTextNode(expandHtmlEntities(text)); +}; + const safeTextToDOM = function(text, parent) { if ( text === '' ) { return; } @@ -221,7 +225,7 @@ vAPI.i18n.render = function(context) { for ( const elem of root.querySelectorAll('[data-i18n-title]') ) { const text = vAPI.i18n(elem.getAttribute('data-i18n-title')); if ( !text ) { continue; } - elem.setAttribute('title', text); + elem.setAttribute('title', expandHtmlEntities(text)); } for ( const elem of root.querySelectorAll('[placeholder]') ) {