aboutsummaryrefslogtreecommitdiff
path: root/background
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-06-10 14:53:31 +0200
committerWojtek Kosior <koszko@koszko.org>2022-06-10 14:53:31 +0200
commit051d2472407c1dc1e6c2b88a00be04fe77da8919 (patch)
treedaec6d822a65d9e9747a69a692fd608419cc8e0a /background
parentf8dedf60638bffde3f92116db3f418d2e6260e80 (diff)
parentd9441412a6052e5fb057d01b745208070f8bdfd4 (diff)
downloadbrowser-extension-051d2472407c1dc1e6c2b88a00be04fe77da8919.tar.gz
browser-extension-051d2472407c1dc1e6c2b88a00be04fe77da8919.zip
merge support for CORS bypassing and eval()
Diffstat (limited to 'background')
-rw-r--r--background/stream_filter.js13
1 files changed, 9 insertions, 4 deletions
diff --git a/background/stream_filter.js b/background/stream_filter.js
index 921523a..b7879ea 100644
--- a/background/stream_filter.js
+++ b/background/stream_filter.js
@@ -35,7 +35,7 @@
function validate_encoding(charset)
{
try {
- new TextDecoder();
+ new TextDecoder(charset);
return charset;
} catch(e) {
return undefined;
@@ -44,7 +44,7 @@ function validate_encoding(charset)
function is_content_type_header(header)
{
- header.name.toLowerCase().trim() === "content-type";
+ return header.name.toLowerCase().trim() === "content-type";
}
const charset_reg = /;\s*charset\s*=\s*([\w-]+)/i;
@@ -55,7 +55,8 @@ function properties_from_headers(headers)
for (const header of headers.filter(is_content_type_header)) {
const match = charset_reg.exec(header.value);
- if (!properties.detected_charset && validate_encoding(match[1]))
+ if (match && !properties.detected_charset &&
+ validate_encoding(match[1]))
properties.detected_charset = match[1];
if (/html/i.test(header.value))
@@ -105,7 +106,11 @@ function charset_from_meta_tags(doc)
function create_decoder(properties, data)
{
let charset = charset_from_BOM(data) || properties.detected_charset;
- if (!charset && data.indexOf(0) !== -1) {
+
+ if (charset)
+ return new TextDecoder(charset);
+
+ if (data.indexOf(0) !== -1) {
console.warn("Haketilo: zeroes in bytestream, probable cached encoding mismatch. Trying to decode it as UTF-16.",
properties);
return new TextDecoder("utf-16be");