Use charset of the response header in the initial TextDecoder (#1646)

This commit is contained in:
nobody 2024-09-23 08:37:26 +02:00
parent 6ec375a39f
commit e13060e929
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
2 changed files with 5 additions and 3 deletions

View File

@ -52,7 +52,7 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) {
if (!isAllowlisted && mimeType === 'text/html') {
let asciiDecoder, decoder, encoder, charset, isFirstData, filter, data;
let initDecoder, decoder, encoder, charset, isFirstData, filter, data;
charset = (/charset\s*=/).test(header.value) && header.value.replace(/^.*?charset\s*=\s*/, '').replace(/["']?/g, '');
@ -63,7 +63,8 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) {
return;
}
asciiDecoder = new TextDecoder('ASCII');
// Use charset of the response header in the initial TextDecoder. ASCII only as fallback.
initDecoder = new TextDecoder(charset === false ? 'ASCII' : charset);
encoder = new TextEncoder();
isFirstData = true;
filter = browser.webRequest.filterResponseData(details.requestId);
@ -92,7 +93,7 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) {
uint8View = new Uint8Array(chunk);
}
htmlHead = asciiDecoder.decode(uint8View, {'stream': false});
htmlHead = initDecoder.decode(uint8View, {'stream': false});
// eslint-disable-next-line no-useless-escape
charsetMatch = htmlHead.match(/<meta\s+charset=["']?([^>"'\/]+)["'>\/]/i);
if (charsetMatch === null) {

View File

@ -28,6 +28,7 @@
<p>Improved</p>
<ul>
<li>redirect outdated paths of font-awesome</li>
<li>Use charset of the response header in the initial TextDecoder. (<a href="https://codeberg.org/nobody/LocalCDN/issues/1646">#1646</a>)</li>
</ul>
<p>Mapping</p>
<ul>