1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

#1735: remove spurious whitespaces from data URI description fields

This commit is contained in:
gorhill 2016-09-15 09:06:22 -04:00
parent 63691a26ef
commit 6e81771783

View File

@ -240,10 +240,25 @@ vAPI.tabs.registerListeners = function() {
// http://raymondhill.net/ublock/popup.html
var reGoodForWebRequestAPI = /^https?:\/\//;
// https://forums.lanik.us/viewtopic.php?f=62&t=32826
// Chromium-based browsers: sanitize target URL. I've seen
// data: URI-based with newline characters, possibly as a way of
// evading filters. There should be no whitespaces in a data: URI's
// standard fields.
var sanitizeURL = function(url) {
if ( url.startsWith('data:') === false ) { return url; }
var pos = url.indexOf(',');
if ( pos === -1 ) { return url; }
var s = url.slice(0, pos);
if ( s.search(/\s/) === -1 ) { return url; }
return s.replace(/\s+/, '') + url.slice(pos);
};
var onCreatedNavigationTarget = function(details) {
//console.debug('onCreatedNavigationTarget: popup candidate tab id %d = "%s"', details.tabId, details.url);
if ( reGoodForWebRequestAPI.test(details.url) === false ) {
details.frameId = 0;
details.url = sanitizeURL(details.url);
onNavigationClient(details);
}
if ( typeof vAPI.tabs.onPopupCreated === 'function' ) {
@ -261,6 +276,7 @@ vAPI.tabs.registerListeners = function() {
if ( details.frameId !== 0 ) {
return;
}
details.url = sanitizeURL(details.url);
onNavigationClient(details);
};
@ -269,6 +285,9 @@ vAPI.tabs.registerListeners = function() {
};
var onUpdated = function(tabId, changeInfo, tab) {
if ( changeInfo.url ) {
changeInfo.url = sanitizeURL(changeInfo.url);
}
onUpdatedClient(tabId, changeInfo, tab);
};