1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-06 02:42:33 +01:00
Raymond Hill 2018-07-30 08:56:51 -04:00
parent 756288294d
commit ec8e1cca15
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -79,16 +79,27 @@ var safeTextToTagNode = function(text) {
}
};
var safeTextToTextNode = function(text) {
// TODO: remove once no more HTML entities in translation files.
var safeTextToTextNode = (function() {
let entities = new Map([
// TODO: Remove quote entities once no longer present in translation
// files. Other entities must stay.
[ '“', '“' ],
[ '”', '”' ],
[ '‘', '' ],
[ '’', '' ],
[ '&lt;', '<' ],
[ '&gt;', '>' ],
]);
let decodeEntities = match => {
return entities.get(match) || match;
};
return function(text) {
if ( text.indexOf('&') !== -1 ) {
text = text.replace(/&ldquo;/g, '“')
.replace(/&rdquo;/g, '”')
.replace(/&lsquo;/g, '')
.replace(/&rsquo;/g, '');
text = text.replace(/&[a-z]+;/g, decodeEntities);
}
return document.createTextNode(text);
};
})();
var safeTextToDOM = function(text, parent) {
if ( text === '' ) { return; }