From 8cf87061f4bb7ef6b053a101eb99b2848fa60f92 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 1 Mar 2018 14:12:16 -0500 Subject: [PATCH] fix #3562 --- src/js/traffic.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/js/traffic.js b/src/js/traffic.js index 3d4bf0ba3..8d2acf38f 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -603,9 +603,16 @@ var filterDocument = (function() { return textDecoder.decode(buffer); }; - var reContentTypeDocument = /^(?:text\/html|application\/xhtml+xml)/i, + var reContentTypeDocument = /^(?:text\/html|application\/xhtml\+xml)/i, reContentTypeCharset = /charset=['"]?([^'" ]+)/i; + var mimeFromContentType = function(contentType) { + var match = reContentTypeDocument.exec(contentType); + if ( match !== null ) { + return match[0].toLowerCase(); + } + }; + var charsetFromContentType = function(contentType) { var match = reContentTypeCharset.exec(contentType); if ( match !== null ) { @@ -786,7 +793,7 @@ var filterDocument = (function() { } doc = domParser.parseFromString( utf8TextDecoder.decode(filterer.buffer.slice(0, 1024)), - 'text/html' + filterer.mime ); charsetFound = charsetFromDoc(doc); charsetUsed = µb.textEncode.normalizeCharset(charsetFound); @@ -797,7 +804,7 @@ var filterDocument = (function() { doc = domParser.parseFromString( textDecode(charsetUsed, filterer.buffer), - 'text/html' + filterer.mime ); // https://github.com/gorhill/uBlock/issues/3507 @@ -812,7 +819,7 @@ var filterDocument = (function() { charsetUsed = charsetFound; doc = domParser.parseFromString( textDecode(charsetFound, filterer.buffer), - 'text/html' + filterer.mime ); } } @@ -879,6 +886,7 @@ var filterDocument = (function() { selectors: undefined, scriptlets: undefined, buffer: null, + mime: undefined, charset: undefined }; @@ -906,7 +914,8 @@ var filterDocument = (function() { var headers = details.responseHeaders, contentType = headerValueFromName('content-type', headers); if ( contentType !== '' ) { - if ( reContentTypeDocument.test(contentType) === false ) { return; } + request.mime = mimeFromContentType(contentType); + if ( request.mime === undefined ) { return; } var charset = charsetFromContentType(contentType); if ( charset !== undefined ) { charset = µb.textEncode.normalizeCharset(charset);