Skip to content

Commit c96a673

Browse files
committed
Bring header= filter option out of experimental status
Related commits: - bde3164 - 5db8d05 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
1 parent 7af88b0 commit c96a673

File tree

11 files changed

+16
-37
lines changed

11 files changed

+16
-37
lines changed

‎src/js/1p-filters.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ let cachedUserFilters = '';
7070
if ( response instanceof Object === false ) { return; }
7171
if ( response.hintUpdateToken !== undefined ) {
7272
const mode = cmEditor.getMode();
73-
if ( typeof response.filterOnHeaders === 'boolean' ) {
74-
cmEditor.setOption('filterOnHeaders', response.filterOnHeaders);
75-
}
7673
if ( mode.setHints instanceof Function ) {
7774
mode.setHints(response);
7875
}

‎src/js/asset-viewer.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ import './codemirror/ubo-static-filtering.js';
7373
});
7474
if ( hints instanceof Object ) {
7575
const mode = cmEditor.getMode();
76-
cmEditor.setOption('filterOnHeaders', hints.filterOnHeaders === true);
7776
if ( mode.setHints instanceof Function ) {
7877
mode.setHints(hints);
7978
}

‎src/js/background.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ const hiddenSettingsDefault = {
7171
disableWebAssembly: false,
7272
extensionUpdateForceReload: false,
7373
filterAuthorMode: false,
74-
filterOnHeaders: false,
7574
loggerPopupType: 'popup',
7675
manualUpdateAssetFetchPeriod: 500,
7776
modifyWebextFlavor: 'unset',

‎src/js/benchmarks.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const loadBenchmarkDataset = (( ) => {
188188
staticNetFilteringEngine.matchAndFetchModifiers(fctxt, 'csp');
189189
staticNetFilteringEngine.matchAndFetchModifiers(fctxt, 'permissions');
190190
}
191-
//staticNetFilteringEngine.matchHeaders(fctxt, []);
191+
staticNetFilteringEngine.matchHeaders(fctxt, []);
192192
} else if ( redirectEngine !== undefined ) {
193193
staticNetFilteringEngine.redirectRequest(redirectEngine, fctxt);
194194
}

‎src/js/codemirror/ubo-static-filtering.js‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ const originHints = [];
3838
let hintHelperRegistered = false;
3939

4040

41-
/******************************************************************************/
42-
43-
let filterOnHeaders = false;
44-
45-
CodeMirror.defineOption('filterOnHeaders', false, (cm, state) => {
46-
filterOnHeaders = state;
47-
self.dispatchEvent(new Event('filterOnHeaders'));
48-
});
49-
5041
/******************************************************************************/
5142

5243
CodeMirror.defineMode('ubo-static-filtering', function() {
@@ -214,10 +205,6 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
214205
return '+';
215206
};
216207

217-
self.addEventListener('filterOnHeaders', ( ) => {
218-
astParser.options.filterOnHeaders = filterOnHeaders;
219-
});
220-
221208
return {
222209
lineComment: '!',
223210
token: function(stream) {
@@ -990,10 +977,6 @@ CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => {
990977
}
991978
};
992979

993-
self.addEventListener('filterOnHeaders', ( ) => {
994-
astParser.options.filterOnHeaders = filterOnHeaders;
995-
});
996-
997980
CodeMirror.defineInitHook(cm => {
998981
cm.on('changes', onChanges);
999982
cm.on('beforeChange', onBeforeChanges);

‎src/js/messaging.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,6 @@ const onMessage = function(request, sender, callback) {
16001600
response.preparseDirectiveHints =
16011601
sfp.utils.preparser.getHints();
16021602
response.expertMode = µb.hiddenSettings.filterAuthorMode;
1603-
response.filterOnHeaders = µb.hiddenSettings.filterOnHeaders;
16041603
}
16051604
if ( request.hintUpdateToken !== µb.pageStoresToken ) {
16061605
response.originHints = getOriginHints();

‎src/js/reverselookup.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ const fromNetFilter = async function(rawFilter) {
131131
const writer = new CompiledListWriter();
132132
const parser = new sfp.AstFilterParser({
133133
expertMode: true,
134-
filterOnHeaders: true,
135134
maxTokenLength: staticNetFilteringEngine.MAX_TOKEN_LENGTH,
136135
nativeCssHas: vAPI.webextFlavor.env.includes('native_css_has'),
137136
});

‎src/js/static-filtering-parser.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ export class AstFilterParser {
12791279
realBad = isException === false || isNegated || hasValue;
12801280
break;
12811281
case NODE_TYPE_NET_OPTION_NAME_HEADER:
1282-
realBad = this.options.filterOnHeaders !== true || isNegated || hasValue === false;
1282+
realBad = isNegated || hasValue === false;
12831283
break;
12841284
case NODE_TYPE_NET_OPTION_NAME_IMPORTANT:
12851285
realBad = isException || isNegated || hasValue;

‎src/js/static-net-filtering.js‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,25 +5000,25 @@ FilterContainer.prototype.realmMatchString = function(
50005000
let tokenHash = DOT_TOKEN_HASH;
50015001
if (
50025002
(ibucket00 !== 0) &&
5003-
(iunit = bucket00.get(tokenHash) || 0) !== 0 &&
5003+
(iunit = bucket00.get(DOT_TOKEN_HASH) || 0) !== 0 &&
50045004
(filterMatch(iunit) === true)
50055005
) {
50065006
catBits = catBits00;
50075007
} else if (
50085008
(ibucket01 !== 0) &&
5009-
(iunit = bucket01.get(tokenHash) || 0) !== 0 &&
5009+
(iunit = bucket01.get(DOT_TOKEN_HASH) || 0) !== 0 &&
50105010
(filterMatch(iunit) === true)
50115011
) {
50125012
catBits = catBits01;
50135013
} else if (
50145014
(ibucket10 !== 0) &&
5015-
(iunit = bucket10.get(tokenHash) || 0) !== 0 &&
5015+
(iunit = bucket10.get(DOT_TOKEN_HASH) || 0) !== 0 &&
50165016
(filterMatch(iunit) === true)
50175017
) {
50185018
catBits = catBits10;
50195019
} else if (
50205020
(ibucket11 !== 0) &&
5021-
(iunit = bucket11.get(tokenHash) || 0) !== 0 &&
5021+
(iunit = bucket11.get(DOT_TOKEN_HASH) || 0) !== 0 &&
50225022
(filterMatch(iunit) === true)
50235023
) {
50245024
catBits = catBits11;
@@ -5200,12 +5200,16 @@ FilterContainer.prototype.matchHeaders = function(fctxt, headers) {
52005200
$httpHeaders.init(headers);
52015201

52025202
let r = 0;
5203-
if ( this.realmMatchString(HEADERS | BlockImportant, typeBits, partyBits) ) {
5203+
if ( this.realmMatchString(HEADERS | BlockAction, typeBits, partyBits) ) {
52045204
r = 1;
5205-
} else if ( this.realmMatchString(HEADERS | BlockAction, typeBits, partyBits) ) {
5206-
r = this.realmMatchString(HEADERS | AllowAction, typeBits, partyBits)
5207-
? 2
5208-
: 1;
5205+
}
5206+
if ( r !== 0 && $isBlockImportant !== true ) {
5207+
if ( this.realmMatchString(HEADERS | AllowAction, typeBits, partyBits) ) {
5208+
r = 2;
5209+
if ( this.realmMatchString(HEADERS | BlockImportant, typeBits, partyBits) ) {
5210+
r = 1;
5211+
}
5212+
}
52095213
}
52105214

52115215
$httpHeaders.reset();

‎src/js/storage.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
10511051
this.hiddenSettings.filterAuthorMode !== false;
10521052
const parser = new sfp.AstFilterParser({
10531053
expertMode,
1054-
filterOnHeaders: µb.hiddenSettings.filterOnHeaders,
10551054
maxTokenLength: staticNetFilteringEngine.MAX_TOKEN_LENGTH,
10561055
nativeCssHas: vAPI.webextFlavor.env.includes('native_css_has'),
10571056
});

0 commit comments

Comments
 (0)