mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-01 08:39:37 +02:00
Bring header=
filter option out of experimental status
Related commits: -bde3164eb4
-5db8d05975
Reference documentation: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#header Compatible with AdGuard's `header=` option: https://adguard.com/kb/general/ad-filtering/create-own-filters/#header-modifier Partially compatible with ABP's `header=` option: Not compatible if a header value is specified, as ABP requires `=` as separator between the header name and header value, whereas uBO and AdGuard require `:` as separator. If no header value is present, the option becomes compatible with ABP's syntax. https://gitlab.com/adblockinc/ext/adblockplus/adblockplusui/-/issues/898
This commit is contained in:
parent
7af88b025d
commit
c96a673338
@ -70,9 +70,6 @@ let cachedUserFilters = '';
|
||||
if ( response instanceof Object === false ) { return; }
|
||||
if ( response.hintUpdateToken !== undefined ) {
|
||||
const mode = cmEditor.getMode();
|
||||
if ( typeof response.filterOnHeaders === 'boolean' ) {
|
||||
cmEditor.setOption('filterOnHeaders', response.filterOnHeaders);
|
||||
}
|
||||
if ( mode.setHints instanceof Function ) {
|
||||
mode.setHints(response);
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ import './codemirror/ubo-static-filtering.js';
|
||||
});
|
||||
if ( hints instanceof Object ) {
|
||||
const mode = cmEditor.getMode();
|
||||
cmEditor.setOption('filterOnHeaders', hints.filterOnHeaders === true);
|
||||
if ( mode.setHints instanceof Function ) {
|
||||
mode.setHints(hints);
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ const hiddenSettingsDefault = {
|
||||
disableWebAssembly: false,
|
||||
extensionUpdateForceReload: false,
|
||||
filterAuthorMode: false,
|
||||
filterOnHeaders: false,
|
||||
loggerPopupType: 'popup',
|
||||
manualUpdateAssetFetchPeriod: 500,
|
||||
modifyWebextFlavor: 'unset',
|
||||
|
@ -188,7 +188,7 @@ const loadBenchmarkDataset = (( ) => {
|
||||
staticNetFilteringEngine.matchAndFetchModifiers(fctxt, 'csp');
|
||||
staticNetFilteringEngine.matchAndFetchModifiers(fctxt, 'permissions');
|
||||
}
|
||||
//staticNetFilteringEngine.matchHeaders(fctxt, []);
|
||||
staticNetFilteringEngine.matchHeaders(fctxt, []);
|
||||
} else if ( redirectEngine !== undefined ) {
|
||||
staticNetFilteringEngine.redirectRequest(redirectEngine, fctxt);
|
||||
}
|
||||
|
@ -38,15 +38,6 @@ const originHints = [];
|
||||
let hintHelperRegistered = false;
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
let filterOnHeaders = false;
|
||||
|
||||
CodeMirror.defineOption('filterOnHeaders', false, (cm, state) => {
|
||||
filterOnHeaders = state;
|
||||
self.dispatchEvent(new Event('filterOnHeaders'));
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
CodeMirror.defineMode('ubo-static-filtering', function() {
|
||||
@ -214,10 +205,6 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
|
||||
return '+';
|
||||
};
|
||||
|
||||
self.addEventListener('filterOnHeaders', ( ) => {
|
||||
astParser.options.filterOnHeaders = filterOnHeaders;
|
||||
});
|
||||
|
||||
return {
|
||||
lineComment: '!',
|
||||
token: function(stream) {
|
||||
@ -990,10 +977,6 @@ CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => {
|
||||
}
|
||||
};
|
||||
|
||||
self.addEventListener('filterOnHeaders', ( ) => {
|
||||
astParser.options.filterOnHeaders = filterOnHeaders;
|
||||
});
|
||||
|
||||
CodeMirror.defineInitHook(cm => {
|
||||
cm.on('changes', onChanges);
|
||||
cm.on('beforeChange', onBeforeChanges);
|
||||
|
@ -1600,7 +1600,6 @@ const onMessage = function(request, sender, callback) {
|
||||
response.preparseDirectiveHints =
|
||||
sfp.utils.preparser.getHints();
|
||||
response.expertMode = µb.hiddenSettings.filterAuthorMode;
|
||||
response.filterOnHeaders = µb.hiddenSettings.filterOnHeaders;
|
||||
}
|
||||
if ( request.hintUpdateToken !== µb.pageStoresToken ) {
|
||||
response.originHints = getOriginHints();
|
||||
|
@ -131,7 +131,6 @@ const fromNetFilter = async function(rawFilter) {
|
||||
const writer = new CompiledListWriter();
|
||||
const parser = new sfp.AstFilterParser({
|
||||
expertMode: true,
|
||||
filterOnHeaders: true,
|
||||
maxTokenLength: staticNetFilteringEngine.MAX_TOKEN_LENGTH,
|
||||
nativeCssHas: vAPI.webextFlavor.env.includes('native_css_has'),
|
||||
});
|
||||
|
@ -1279,7 +1279,7 @@ export class AstFilterParser {
|
||||
realBad = isException === false || isNegated || hasValue;
|
||||
break;
|
||||
case NODE_TYPE_NET_OPTION_NAME_HEADER:
|
||||
realBad = this.options.filterOnHeaders !== true || isNegated || hasValue === false;
|
||||
realBad = isNegated || hasValue === false;
|
||||
break;
|
||||
case NODE_TYPE_NET_OPTION_NAME_IMPORTANT:
|
||||
realBad = isException || isNegated || hasValue;
|
||||
|
@ -5000,25 +5000,25 @@ FilterContainer.prototype.realmMatchString = function(
|
||||
let tokenHash = DOT_TOKEN_HASH;
|
||||
if (
|
||||
(ibucket00 !== 0) &&
|
||||
(iunit = bucket00.get(tokenHash) || 0) !== 0 &&
|
||||
(iunit = bucket00.get(DOT_TOKEN_HASH) || 0) !== 0 &&
|
||||
(filterMatch(iunit) === true)
|
||||
) {
|
||||
catBits = catBits00;
|
||||
} else if (
|
||||
(ibucket01 !== 0) &&
|
||||
(iunit = bucket01.get(tokenHash) || 0) !== 0 &&
|
||||
(iunit = bucket01.get(DOT_TOKEN_HASH) || 0) !== 0 &&
|
||||
(filterMatch(iunit) === true)
|
||||
) {
|
||||
catBits = catBits01;
|
||||
} else if (
|
||||
(ibucket10 !== 0) &&
|
||||
(iunit = bucket10.get(tokenHash) || 0) !== 0 &&
|
||||
(iunit = bucket10.get(DOT_TOKEN_HASH) || 0) !== 0 &&
|
||||
(filterMatch(iunit) === true)
|
||||
) {
|
||||
catBits = catBits10;
|
||||
} else if (
|
||||
(ibucket11 !== 0) &&
|
||||
(iunit = bucket11.get(tokenHash) || 0) !== 0 &&
|
||||
(iunit = bucket11.get(DOT_TOKEN_HASH) || 0) !== 0 &&
|
||||
(filterMatch(iunit) === true)
|
||||
) {
|
||||
catBits = catBits11;
|
||||
@ -5200,12 +5200,16 @@ FilterContainer.prototype.matchHeaders = function(fctxt, headers) {
|
||||
$httpHeaders.init(headers);
|
||||
|
||||
let r = 0;
|
||||
if ( this.realmMatchString(HEADERS | BlockImportant, typeBits, partyBits) ) {
|
||||
if ( this.realmMatchString(HEADERS | BlockAction, typeBits, partyBits) ) {
|
||||
r = 1;
|
||||
} else if ( this.realmMatchString(HEADERS | BlockAction, typeBits, partyBits) ) {
|
||||
r = this.realmMatchString(HEADERS | AllowAction, typeBits, partyBits)
|
||||
? 2
|
||||
: 1;
|
||||
}
|
||||
if ( r !== 0 && $isBlockImportant !== true ) {
|
||||
if ( this.realmMatchString(HEADERS | AllowAction, typeBits, partyBits) ) {
|
||||
r = 2;
|
||||
if ( this.realmMatchString(HEADERS | BlockImportant, typeBits, partyBits) ) {
|
||||
r = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$httpHeaders.reset();
|
||||
|
@ -1051,7 +1051,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
||||
this.hiddenSettings.filterAuthorMode !== false;
|
||||
const parser = new sfp.AstFilterParser({
|
||||
expertMode,
|
||||
filterOnHeaders: µb.hiddenSettings.filterOnHeaders,
|
||||
maxTokenLength: staticNetFilteringEngine.MAX_TOKEN_LENGTH,
|
||||
nativeCssHas: vAPI.webextFlavor.env.includes('native_css_has'),
|
||||
});
|
||||
|
@ -516,7 +516,7 @@ const onHeadersReceived = function(details) {
|
||||
const { responseHeaders } = details;
|
||||
if ( Array.isArray(responseHeaders) === false ) { return; }
|
||||
|
||||
if ( isRootDoc === false && µb.hiddenSettings.filterOnHeaders === true ) {
|
||||
if ( isRootDoc === false ) {
|
||||
const result = pageStore.filterOnHeaders(fctxt, responseHeaders);
|
||||
if ( result !== 0 ) {
|
||||
if ( logger.enabled ) {
|
||||
|
Loading…
Reference in New Issue
Block a user