mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-14 23:12:28 +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 instanceof Object === false ) { return; }
|
||||||
if ( response.hintUpdateToken !== undefined ) {
|
if ( response.hintUpdateToken !== undefined ) {
|
||||||
const mode = cmEditor.getMode();
|
const mode = cmEditor.getMode();
|
||||||
if ( typeof response.filterOnHeaders === 'boolean' ) {
|
|
||||||
cmEditor.setOption('filterOnHeaders', response.filterOnHeaders);
|
|
||||||
}
|
|
||||||
if ( mode.setHints instanceof Function ) {
|
if ( mode.setHints instanceof Function ) {
|
||||||
mode.setHints(response);
|
mode.setHints(response);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,6 @@ import './codemirror/ubo-static-filtering.js';
|
|||||||
});
|
});
|
||||||
if ( hints instanceof Object ) {
|
if ( hints instanceof Object ) {
|
||||||
const mode = cmEditor.getMode();
|
const mode = cmEditor.getMode();
|
||||||
cmEditor.setOption('filterOnHeaders', hints.filterOnHeaders === true);
|
|
||||||
if ( mode.setHints instanceof Function ) {
|
if ( mode.setHints instanceof Function ) {
|
||||||
mode.setHints(hints);
|
mode.setHints(hints);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,6 @@ const hiddenSettingsDefault = {
|
|||||||
disableWebAssembly: false,
|
disableWebAssembly: false,
|
||||||
extensionUpdateForceReload: false,
|
extensionUpdateForceReload: false,
|
||||||
filterAuthorMode: false,
|
filterAuthorMode: false,
|
||||||
filterOnHeaders: false,
|
|
||||||
loggerPopupType: 'popup',
|
loggerPopupType: 'popup',
|
||||||
manualUpdateAssetFetchPeriod: 500,
|
manualUpdateAssetFetchPeriod: 500,
|
||||||
modifyWebextFlavor: 'unset',
|
modifyWebextFlavor: 'unset',
|
||||||
|
@ -188,7 +188,7 @@ const loadBenchmarkDataset = (( ) => {
|
|||||||
staticNetFilteringEngine.matchAndFetchModifiers(fctxt, 'csp');
|
staticNetFilteringEngine.matchAndFetchModifiers(fctxt, 'csp');
|
||||||
staticNetFilteringEngine.matchAndFetchModifiers(fctxt, 'permissions');
|
staticNetFilteringEngine.matchAndFetchModifiers(fctxt, 'permissions');
|
||||||
}
|
}
|
||||||
//staticNetFilteringEngine.matchHeaders(fctxt, []);
|
staticNetFilteringEngine.matchHeaders(fctxt, []);
|
||||||
} else if ( redirectEngine !== undefined ) {
|
} else if ( redirectEngine !== undefined ) {
|
||||||
staticNetFilteringEngine.redirectRequest(redirectEngine, fctxt);
|
staticNetFilteringEngine.redirectRequest(redirectEngine, fctxt);
|
||||||
}
|
}
|
||||||
|
@ -38,15 +38,6 @@ const originHints = [];
|
|||||||
let hintHelperRegistered = false;
|
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() {
|
CodeMirror.defineMode('ubo-static-filtering', function() {
|
||||||
@ -214,10 +205,6 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
|
|||||||
return '+';
|
return '+';
|
||||||
};
|
};
|
||||||
|
|
||||||
self.addEventListener('filterOnHeaders', ( ) => {
|
|
||||||
astParser.options.filterOnHeaders = filterOnHeaders;
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
lineComment: '!',
|
lineComment: '!',
|
||||||
token: function(stream) {
|
token: function(stream) {
|
||||||
@ -990,10 +977,6 @@ CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.addEventListener('filterOnHeaders', ( ) => {
|
|
||||||
astParser.options.filterOnHeaders = filterOnHeaders;
|
|
||||||
});
|
|
||||||
|
|
||||||
CodeMirror.defineInitHook(cm => {
|
CodeMirror.defineInitHook(cm => {
|
||||||
cm.on('changes', onChanges);
|
cm.on('changes', onChanges);
|
||||||
cm.on('beforeChange', onBeforeChanges);
|
cm.on('beforeChange', onBeforeChanges);
|
||||||
|
@ -1600,7 +1600,6 @@ const onMessage = function(request, sender, callback) {
|
|||||||
response.preparseDirectiveHints =
|
response.preparseDirectiveHints =
|
||||||
sfp.utils.preparser.getHints();
|
sfp.utils.preparser.getHints();
|
||||||
response.expertMode = µb.hiddenSettings.filterAuthorMode;
|
response.expertMode = µb.hiddenSettings.filterAuthorMode;
|
||||||
response.filterOnHeaders = µb.hiddenSettings.filterOnHeaders;
|
|
||||||
}
|
}
|
||||||
if ( request.hintUpdateToken !== µb.pageStoresToken ) {
|
if ( request.hintUpdateToken !== µb.pageStoresToken ) {
|
||||||
response.originHints = getOriginHints();
|
response.originHints = getOriginHints();
|
||||||
|
@ -131,7 +131,6 @@ const fromNetFilter = async function(rawFilter) {
|
|||||||
const writer = new CompiledListWriter();
|
const writer = new CompiledListWriter();
|
||||||
const parser = new sfp.AstFilterParser({
|
const parser = new sfp.AstFilterParser({
|
||||||
expertMode: true,
|
expertMode: true,
|
||||||
filterOnHeaders: true,
|
|
||||||
maxTokenLength: staticNetFilteringEngine.MAX_TOKEN_LENGTH,
|
maxTokenLength: staticNetFilteringEngine.MAX_TOKEN_LENGTH,
|
||||||
nativeCssHas: vAPI.webextFlavor.env.includes('native_css_has'),
|
nativeCssHas: vAPI.webextFlavor.env.includes('native_css_has'),
|
||||||
});
|
});
|
||||||
|
@ -1279,7 +1279,7 @@ export class AstFilterParser {
|
|||||||
realBad = isException === false || isNegated || hasValue;
|
realBad = isException === false || isNegated || hasValue;
|
||||||
break;
|
break;
|
||||||
case NODE_TYPE_NET_OPTION_NAME_HEADER:
|
case NODE_TYPE_NET_OPTION_NAME_HEADER:
|
||||||
realBad = this.options.filterOnHeaders !== true || isNegated || hasValue === false;
|
realBad = isNegated || hasValue === false;
|
||||||
break;
|
break;
|
||||||
case NODE_TYPE_NET_OPTION_NAME_IMPORTANT:
|
case NODE_TYPE_NET_OPTION_NAME_IMPORTANT:
|
||||||
realBad = isException || isNegated || hasValue;
|
realBad = isException || isNegated || hasValue;
|
||||||
|
@ -5000,25 +5000,25 @@ FilterContainer.prototype.realmMatchString = function(
|
|||||||
let tokenHash = DOT_TOKEN_HASH;
|
let tokenHash = DOT_TOKEN_HASH;
|
||||||
if (
|
if (
|
||||||
(ibucket00 !== 0) &&
|
(ibucket00 !== 0) &&
|
||||||
(iunit = bucket00.get(tokenHash) || 0) !== 0 &&
|
(iunit = bucket00.get(DOT_TOKEN_HASH) || 0) !== 0 &&
|
||||||
(filterMatch(iunit) === true)
|
(filterMatch(iunit) === true)
|
||||||
) {
|
) {
|
||||||
catBits = catBits00;
|
catBits = catBits00;
|
||||||
} else if (
|
} else if (
|
||||||
(ibucket01 !== 0) &&
|
(ibucket01 !== 0) &&
|
||||||
(iunit = bucket01.get(tokenHash) || 0) !== 0 &&
|
(iunit = bucket01.get(DOT_TOKEN_HASH) || 0) !== 0 &&
|
||||||
(filterMatch(iunit) === true)
|
(filterMatch(iunit) === true)
|
||||||
) {
|
) {
|
||||||
catBits = catBits01;
|
catBits = catBits01;
|
||||||
} else if (
|
} else if (
|
||||||
(ibucket10 !== 0) &&
|
(ibucket10 !== 0) &&
|
||||||
(iunit = bucket10.get(tokenHash) || 0) !== 0 &&
|
(iunit = bucket10.get(DOT_TOKEN_HASH) || 0) !== 0 &&
|
||||||
(filterMatch(iunit) === true)
|
(filterMatch(iunit) === true)
|
||||||
) {
|
) {
|
||||||
catBits = catBits10;
|
catBits = catBits10;
|
||||||
} else if (
|
} else if (
|
||||||
(ibucket11 !== 0) &&
|
(ibucket11 !== 0) &&
|
||||||
(iunit = bucket11.get(tokenHash) || 0) !== 0 &&
|
(iunit = bucket11.get(DOT_TOKEN_HASH) || 0) !== 0 &&
|
||||||
(filterMatch(iunit) === true)
|
(filterMatch(iunit) === true)
|
||||||
) {
|
) {
|
||||||
catBits = catBits11;
|
catBits = catBits11;
|
||||||
@ -5200,12 +5200,16 @@ FilterContainer.prototype.matchHeaders = function(fctxt, headers) {
|
|||||||
$httpHeaders.init(headers);
|
$httpHeaders.init(headers);
|
||||||
|
|
||||||
let r = 0;
|
let r = 0;
|
||||||
if ( this.realmMatchString(HEADERS | BlockImportant, typeBits, partyBits) ) {
|
if ( this.realmMatchString(HEADERS | BlockAction, typeBits, partyBits) ) {
|
||||||
r = 1;
|
r = 1;
|
||||||
} else if ( this.realmMatchString(HEADERS | BlockAction, typeBits, partyBits) ) {
|
}
|
||||||
r = this.realmMatchString(HEADERS | AllowAction, typeBits, partyBits)
|
if ( r !== 0 && $isBlockImportant !== true ) {
|
||||||
? 2
|
if ( this.realmMatchString(HEADERS | AllowAction, typeBits, partyBits) ) {
|
||||||
: 1;
|
r = 2;
|
||||||
|
if ( this.realmMatchString(HEADERS | BlockImportant, typeBits, partyBits) ) {
|
||||||
|
r = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$httpHeaders.reset();
|
$httpHeaders.reset();
|
||||||
|
@ -1051,7 +1051,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
this.hiddenSettings.filterAuthorMode !== false;
|
this.hiddenSettings.filterAuthorMode !== false;
|
||||||
const parser = new sfp.AstFilterParser({
|
const parser = new sfp.AstFilterParser({
|
||||||
expertMode,
|
expertMode,
|
||||||
filterOnHeaders: µb.hiddenSettings.filterOnHeaders,
|
|
||||||
maxTokenLength: staticNetFilteringEngine.MAX_TOKEN_LENGTH,
|
maxTokenLength: staticNetFilteringEngine.MAX_TOKEN_LENGTH,
|
||||||
nativeCssHas: vAPI.webextFlavor.env.includes('native_css_has'),
|
nativeCssHas: vAPI.webextFlavor.env.includes('native_css_has'),
|
||||||
});
|
});
|
||||||
|
@ -516,7 +516,7 @@ const onHeadersReceived = function(details) {
|
|||||||
const { responseHeaders } = details;
|
const { responseHeaders } = details;
|
||||||
if ( Array.isArray(responseHeaders) === false ) { return; }
|
if ( Array.isArray(responseHeaders) === false ) { return; }
|
||||||
|
|
||||||
if ( isRootDoc === false && µb.hiddenSettings.filterOnHeaders === true ) {
|
if ( isRootDoc === false ) {
|
||||||
const result = pageStore.filterOnHeaders(fctxt, responseHeaders);
|
const result = pageStore.filterOnHeaders(fctxt, responseHeaders);
|
||||||
if ( result !== 0 ) {
|
if ( result !== 0 ) {
|
||||||
if ( logger.enabled ) {
|
if ( logger.enabled ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user