mirror of https://github.com/gorhill/uBlock.git
Harden xml-prune scriptlet
This commit is contained in:
parent
3227d7f591
commit
596145ceb9
|
@ -1692,7 +1692,6 @@
|
||||||
reUrl = new RegExp(urlPattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
reUrl = new RegExp(urlPattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
||||||
}
|
}
|
||||||
const pruner = text => {
|
const pruner = text => {
|
||||||
if ( selector === '' ) { return text; }
|
|
||||||
if ( (/^\s*</.test(text) && />\s*$/.test(text)) === false ) {
|
if ( (/^\s*</.test(text) && />\s*$/.test(text)) === false ) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
@ -1714,16 +1713,25 @@
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
const urlFromArg = arg => {
|
||||||
|
if ( typeof arg === 'string' ) { return arg; }
|
||||||
|
if ( arg instanceof Request ) { return arg.url; }
|
||||||
|
return String(arg);
|
||||||
|
};
|
||||||
const realFetch = self.fetch;
|
const realFetch = self.fetch;
|
||||||
self.fetch = new Proxy(self.fetch, {
|
self.fetch = new Proxy(self.fetch, {
|
||||||
apply: function(target, thisArg, args) {
|
apply: function(target, thisArg, args) {
|
||||||
if ( reUrl.test(String(args[0])) === false ) {
|
if ( selector === '' || reUrl.test(urlFromArg(args[0])) === false ) {
|
||||||
return Reflect.apply(target, thisArg, args);
|
return Reflect.apply(target, thisArg, args);
|
||||||
}
|
}
|
||||||
return realFetch(...args).then(response =>
|
return realFetch(...args).then(realResponse =>
|
||||||
response.text()
|
realResponse.text().then(text =>
|
||||||
).then(text =>
|
new Response(pruner(text), {
|
||||||
new Response(pruner(text))
|
status: realResponse.status,
|
||||||
|
statusText: realResponse.statusText,
|
||||||
|
headers: realResponse.headers,
|
||||||
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue