Skip to content

Commit d8298bb

Browse files
committed
Add support for network filter option message
Related issue: uBlockOrigin/uBlock-issues#1195
1 parent eb3f5a4 commit d8298bb

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

src/js/static-filtering-parser.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export const NODE_TYPE_NET_OPTION_NAME_INLINESCRIPT = iota++;
174174
export const NODE_TYPE_NET_OPTION_NAME_IPADDRESS = iota++;
175175
export const NODE_TYPE_NET_OPTION_NAME_MATCHCASE = iota++;
176176
export const NODE_TYPE_NET_OPTION_NAME_MEDIA = iota++;
177+
export const NODE_TYPE_NET_OPTION_NAME_MESSAGE = iota++;
177178
export const NODE_TYPE_NET_OPTION_NAME_METHOD = iota++;
178179
export const NODE_TYPE_NET_OPTION_NAME_MP4 = iota++;
179180
export const NODE_TYPE_NET_OPTION_NAME_NOOP = iota++;
@@ -255,6 +256,7 @@ export const nodeTypeFromOptionName = new Map([
255256
[ 'ipaddress', NODE_TYPE_NET_OPTION_NAME_IPADDRESS ],
256257
[ 'match-case', NODE_TYPE_NET_OPTION_NAME_MATCHCASE ],
257258
[ 'media', NODE_TYPE_NET_OPTION_NAME_MEDIA ],
259+
[ 'message', NODE_TYPE_NET_OPTION_NAME_MESSAGE ],
258260
[ 'method', NODE_TYPE_NET_OPTION_NAME_METHOD ],
259261
[ 'mp4', NODE_TYPE_NET_OPTION_NAME_MP4 ],
260262
[ '_', NODE_TYPE_NET_OPTION_NAME_NOOP ],
@@ -1350,6 +1352,9 @@ export class AstFilterParser {
13501352
case NODE_TYPE_NET_OPTION_NAME_MATCHCASE:
13511353
realBad = this.isRegexPattern() === false;
13521354
break;
1355+
case NODE_TYPE_NET_OPTION_NAME_MESSAGE:
1356+
realBad = hasValue === false;
1357+
break;
13531358
case NODE_TYPE_NET_OPTION_NAME_PERMISSIONS:
13541359
realBad = modifierType !== 0 ||
13551360
(hasValue || isException) === false ||
@@ -3149,6 +3154,7 @@ export const netOptionTokenDescriptors = new Map([
31493154
[ 'ipaddress', { mustAssign: true } ],
31503155
[ 'match-case', { } ],
31513156
[ 'media', { canNegate: true } ],
3157+
[ 'message', { mustAssign: true } ],
31523158
[ 'method', { mustAssign: true } ],
31533159
[ 'mp4', { blockOnly: true } ],
31543160
[ '_', { } ],

src/js/static-net-filtering.js

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,6 +3103,39 @@ class FilterIPAddress {
31033103

31043104
registerFilterClass(FilterIPAddress);
31053105

3106+
/******************************************************************************/
3107+
3108+
class FilterMessage {
3109+
static match() {
3110+
return true;
3111+
}
3112+
3113+
static compile(details) {
3114+
return [
3115+
FilterMessage.fid,
3116+
encodeURIComponent(details.optionValues.get('message')),
3117+
];
3118+
}
3119+
3120+
static fromCompiled(args) {
3121+
const msg = args[1];
3122+
return filterDataAlloc(args[0], bidiTrie.storeString(msg), msg.length);
3123+
}
3124+
3125+
static keyFromArgs() {
3126+
}
3127+
3128+
static logData(idata, details) {
3129+
const msg = bidiTrie.extractString(
3130+
filterData[idata+1],
3131+
filterData[idata+2]
3132+
);
3133+
details.options.push(`message=${decodeURIComponent(msg)}`);
3134+
}
3135+
}
3136+
3137+
registerFilterClass(FilterMessage);
3138+
31063139
/******************************************************************************/
31073140
/******************************************************************************/
31083141

@@ -3578,6 +3611,10 @@ class FilterCompiler {
35783611
this.optionValues.set('ipaddress', parser.getNetOptionValue(id) || '');
35793612
this.optionUnitBits |= IPADDRESS_BIT;
35803613
break;
3614+
case sfp.NODE_TYPE_NET_OPTION_NAME_MESSAGE:
3615+
this.optionValues.set('message', parser.getNetOptionValue(id));
3616+
this.optionUnitBits |= MESSAGE_BIT;
3617+
break;
35813618
case sfp.NODE_TYPE_NET_OPTION_NAME_METHOD:
35823619
this.processMethodOption(parser.getNetOptionValue(id));
35833620
this.optionUnitBits |= METHOD_BIT;
@@ -3699,6 +3736,7 @@ class FilterCompiler {
36993736
case sfp.NODE_TYPE_NET_OPTION_NAME_FROM:
37003737
case sfp.NODE_TYPE_NET_OPTION_NAME_HEADER:
37013738
case sfp.NODE_TYPE_NET_OPTION_NAME_IPADDRESS:
3739+
case sfp.NODE_TYPE_NET_OPTION_NAME_MESSAGE:
37023740
case sfp.NODE_TYPE_NET_OPTION_NAME_METHOD:
37033741
case sfp.NODE_TYPE_NET_OPTION_NAME_PERMISSIONS:
37043742
case sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECT:
@@ -4081,6 +4119,11 @@ class FilterCompiler {
40814119
this.action |= HEADERS_REALM;
40824120
}
40834121

4122+
// Message
4123+
if ( (this.optionUnitBits & MESSAGE_BIT) !== 0 ) {
4124+
units.push(FilterMessage.compile(this));
4125+
}
4126+
40844127
// Important
40854128
//
40864129
// IMPORTANT: must always appear at the end of the sequence, so as to
@@ -4175,16 +4218,17 @@ class FilterCompiler {
41754218
}
41764219

41774220
// These are to quickly test whether a filter is composite
4178-
const FROM_BIT = 0b0000000001;
4179-
const TO_BIT = 0b0000000010;
4180-
const DENYALLOW_BIT = 0b0000000100;
4181-
const HEADER_BIT = 0b0000001000;
4182-
const STRICT_PARTY_BIT = 0b0000010000;
4183-
const MODIFY_BIT = 0b0000100000;
4184-
const NOT_TYPE_BIT = 0b0001000000;
4185-
const IMPORTANT_BIT = 0b0010000000;
4186-
const METHOD_BIT = 0b0100000000;
4187-
const IPADDRESS_BIT = 0b1000000000;
4221+
const FROM_BIT = 0b00000000001;
4222+
const TO_BIT = 0b00000000010;
4223+
const DENYALLOW_BIT = 0b00000000100;
4224+
const HEADER_BIT = 0b00000001000;
4225+
const STRICT_PARTY_BIT = 0b00000010000;
4226+
const MODIFY_BIT = 0b00000100000;
4227+
const NOT_TYPE_BIT = 0b00001000000;
4228+
const IMPORTANT_BIT = 0b00010000000;
4229+
const METHOD_BIT = 0b00100000000;
4230+
const IPADDRESS_BIT = 0b01000000000;
4231+
const MESSAGE_BIT = 0b10000000000
41884232

41894233
FilterCompiler.prototype.FILTER_OK = 0;
41904234
FilterCompiler.prototype.FILTER_INVALID = 1;

0 commit comments

Comments
 (0)