1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2025-06-05 21:49:31 +02:00

Incorrect insertion of the UTF8 charset in the HTML filter (#782)

This commit is contained in:
nobody
2021-11-24 07:22:11 +01:00
parent 8a068a3941
commit c91d85d53a
2 changed files with 16 additions and 1 deletions

View File

@@ -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