1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-18 18:48:45 +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:
Raymond Hill 2023-10-15 13:17:13 -04:00
parent 7af88b025d
commit c96a673338
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
11 changed files with 16 additions and 37 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -71,7 +71,6 @@ const hiddenSettingsDefault = {
disableWebAssembly: false,
extensionUpdateForceReload: false,
filterAuthorMode: false,
filterOnHeaders: false,
loggerPopupType: 'popup',
manualUpdateAssetFetchPeriod: 500,
modifyWebextFlavor: 'unset',

View File

@ -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);
}

View File

@ -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);

View File

@ -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();

View File

@ -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'),
});

View File

@ -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;

View File

@ -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();

View File

@ -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'),
});

View File

@ -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 ) {