From c91d85d53a9d67e84b82afe5795c0c24af918d00 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 24 Nov 2021 07:22:11 +0100 Subject: [PATCH] Incorrect insertion of the UTF8 charset in the HTML filter (#782) --- core/manipulate-dom.js | 13 ++++++++++++- pages/updates/updates.html | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/manipulate-dom.js b/core/manipulate-dom.js index 78d730e8..c994eda4 100644 --- a/core/manipulate-dom.js +++ b/core/manipulate-dom.js @@ -118,7 +118,7 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) { str += decoder.decode(); // end-of-stream // set UTF-8 in document - str = str.replace(new RegExp(`charset=["']?${charset}["']?`), 'charset="utf8"'); + str = manipulateDOM._searchCharset(str, charset); // remove crossorigin and integrity attributes str = str.replace(/<(link|script)[^>]+>/ig, (m) => { @@ -138,6 +138,17 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) { } }; +manipulateDOM._searchCharset = function (str, charset) { + if (str.indexOf(`charset="${charset}"`) > 0) { + return str.replace(`charset="${charset}"`, 'charset="utf8"'); + } else if (str.indexOf(`charset='${charset}'`) > 0) { + return str.replace(`charset='${charset}'`, 'charset=\'utf8\''); + } else if (str.indexOf(`charset=${charset}`) > 0) { + return str.replace(`charset=${charset}`, 'charset=utf8'); + } else { + return str; + } +}; /** * Initializations diff --git a/pages/updates/updates.html b/pages/updates/updates.html index 5c011c6b..82065e4c 100644 --- a/pages/updates/updates.html +++ b/pages/updates/updates.html @@ -60,6 +60,10 @@
  • i18n: Vietnamese
  • ember.js v4.0.0 (#781)
  • +

    Fixed

    +