@adguard/dnr-converter 1.0.0-alpha.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Popular TLD suffixes used to expand wildcard TLD domains for DNR.
3
+ *
4
+ * Source: manually curated from the IANA Root Zone Database
5
+ * (https://www.iana.org/domains/root/db). "Popular" means broad practical
6
+ * coverage for filter rules: common generic TLDs, commonly registered ccTLDs,
7
+ * common new gTLDs, and TLDs observed in AdGuard filter domain modifiers. This
8
+ * is not a ranked list or a full public suffix list; update it manually when
9
+ * wildcard TLD coverage needs to change.
10
+ *
11
+ * Keep values lowercase, ASCII, and without a leading dot.
12
+ */ const POPULAR_TLDS = [
13
+ 'ac',
14
+ 'ae',
15
+ 'agency',
16
+ 'ai',
17
+ 'am',
18
+ 'app',
19
+ 'ar',
20
+ 'art',
21
+ 'at',
22
+ 'au',
23
+ 'az',
24
+ 'bd',
25
+ 'be',
26
+ 'bg',
27
+ 'biz',
28
+ 'blog',
29
+ 'br',
30
+ 'by',
31
+ 'ca',
32
+ 'cam',
33
+ 'cc',
34
+ 'center',
35
+ 'cfd',
36
+ 'ch',
37
+ 'cl',
38
+ 'click',
39
+ 'cloud',
40
+ 'club',
41
+ 'cn',
42
+ 'co',
43
+ 'co.in',
44
+ 'co.jp',
45
+ 'co.kr',
46
+ 'co.nz',
47
+ 'co.uk',
48
+ 'com',
49
+ 'com.au',
50
+ 'com.br',
51
+ 'com.cn',
52
+ 'com.mx',
53
+ 'com.pl',
54
+ 'com.tr',
55
+ 'com.ua',
56
+ 'company',
57
+ 'cz',
58
+ 'de',
59
+ 'dev',
60
+ 'digital',
61
+ 'dk',
62
+ 'edu',
63
+ 'ee',
64
+ 'eg',
65
+ 'email',
66
+ 'es',
67
+ 'eu',
68
+ 'fi',
69
+ 'fm',
70
+ 'fr',
71
+ 'fun',
72
+ 'ge',
73
+ 'gg',
74
+ 'gov',
75
+ 'gr',
76
+ 'group',
77
+ 'hk',
78
+ 'hr',
79
+ 'hu',
80
+ 'icu',
81
+ 'id',
82
+ 'ie',
83
+ 'il',
84
+ 'im',
85
+ 'in',
86
+ 'info',
87
+ 'ink',
88
+ 'int',
89
+ 'io',
90
+ 'ir',
91
+ 'is',
92
+ 'it',
93
+ 'jobs',
94
+ 'jp',
95
+ 'ke',
96
+ 'kr',
97
+ 'kz',
98
+ 'la',
99
+ 'li',
100
+ 'life',
101
+ 'link',
102
+ 'live',
103
+ 'lk',
104
+ 'lol',
105
+ 'lt',
106
+ 'lu',
107
+ 'lv',
108
+ 'ma',
109
+ 'md',
110
+ 'me',
111
+ 'media',
112
+ 'mil',
113
+ 'mobi',
114
+ 'mx',
115
+ 'my',
116
+ 'name',
117
+ 'net',
118
+ 'net.au',
119
+ 'network',
120
+ 'news',
121
+ 'ng',
122
+ 'nl',
123
+ 'no',
124
+ 'np',
125
+ 'nu',
126
+ 'nz',
127
+ 'one',
128
+ 'onion',
129
+ 'online',
130
+ 'org',
131
+ 'org.uk',
132
+ 'pe',
133
+ 'ph',
134
+ 'pk',
135
+ 'pl',
136
+ 'plus',
137
+ 'porn',
138
+ 'pro',
139
+ 'pt',
140
+ 'pub',
141
+ 'pw',
142
+ 'ro',
143
+ 'rs',
144
+ 'ru',
145
+ 'sa',
146
+ 'sbs',
147
+ 'se',
148
+ 'sg',
149
+ 'shop',
150
+ 'si',
151
+ 'site',
152
+ 'sk',
153
+ 'software',
154
+ 'solutions',
155
+ 'space',
156
+ 'store',
157
+ 'su',
158
+ 'sx',
159
+ 'systems',
160
+ 'tech',
161
+ 'th',
162
+ 'to',
163
+ 'today',
164
+ 'tokyo',
165
+ 'top',
166
+ 'tr',
167
+ 'travel',
168
+ 'tube',
169
+ 'tv',
170
+ 'tw',
171
+ 'ua',
172
+ 'uk',
173
+ 'us',
174
+ 'video',
175
+ 'vip',
176
+ 'vn',
177
+ 'website',
178
+ 'wiki',
179
+ 'win',
180
+ 'work',
181
+ 'world',
182
+ 'ws',
183
+ 'xn--p1ai',
184
+ 'xxx',
185
+ 'xyz',
186
+ 'za',
187
+ 'zone'
188
+ ];
189
+
190
+ export { POPULAR_TLDS };
package/dist/constants.js CHANGED
@@ -16,8 +16,11 @@
16
16
  * This is a wildcard character. It is used to represent "any set of characters".
17
17
  * This can also be an empty string or a string of any length.
18
18
  */ const MASK_ANY_CHARACTER = '*';
19
+ /**
20
+ * Dot character, used as a domain label separator.
21
+ */ const DOT = '.';
19
22
  /**
20
23
  * Space character.
21
24
  */ const SPACE_CHARACTER = ' ';
22
25
 
23
- export { CSP_HEADER_NAME, MASK_ANY_CHARACTER, MASK_NEGATE_CHARACTER, MASK_REGEX_RULE, PERMISSIONS_POLICY_HEADER_NAME, SPACE_CHARACTER };
26
+ export { CSP_HEADER_NAME, DOT, MASK_ANY_CHARACTER, MASK_NEGATE_CHARACTER, MASK_REGEX_RULE, PERMISSIONS_POLICY_HEADER_NAME, SPACE_CHARACTER };
@@ -1,3 +1,3 @@
1
- var version = "1.0.0-alpha.2";
1
+ var version = "1.1.1";
2
2
 
3
3
  export { version };
@@ -33,6 +33,7 @@
33
33
  MEDIA: 'media',
34
34
  FONT: 'font',
35
35
  WEBSOCKET: 'websocket',
36
+ WEBRTC: 'webrtc',
36
37
  OTHER: 'other',
37
38
  PING: 'ping',
38
39
  BADFILTER: 'badfilter',
@@ -44,6 +45,7 @@
44
45
  REMOVEPARAM: 'removeparam',
45
46
  REMOVEHEADER: 'removeheader',
46
47
  JSONPRUNE: 'jsonprune',
48
+ XMLPRUNE: 'xmlprune',
47
49
  HLS: 'hls',
48
50
  REFERRERPOLICY: 'referrerpolicy',
49
51
  APP: 'app',
@@ -420,10 +420,18 @@ name)=>{
420
420
  name: '$jsonprune',
421
421
  notSupported: true
422
422
  },
423
+ [OPTION_NAMES.XMLPRUNE]: {
424
+ name: '$xmlprune',
425
+ notSupported: true
426
+ },
423
427
  [OPTION_NAMES.HLS]: {
424
428
  name: '$hls',
425
429
  notSupported: true
426
430
  },
431
+ [OPTION_NAMES.WEBRTC]: {
432
+ name: '$webrtc',
433
+ notSupported: true
434
+ },
427
435
  // DNS modifiers.
428
436
  [OPTION_NAMES.CLIENT]: {
429
437
  name: '$client',
package/dist/rule/rule.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RuleParser, RuleCategory, NetworkRuleType } from '@adguard/agtree';
1
+ import { DomainListParser, RuleParser, RuleCategory, NetworkRuleType } from '@adguard/agtree';
2
2
  import { RuleConverter } from '@adguard/agtree/converter';
3
3
  import { RuleGenerator } from '@adguard/agtree/generator';
4
4
  import { MASK_REGEX_RULE } from '../constants.js';
@@ -9,6 +9,9 @@ import { OPTION_NAMES } from './option-names.js';
9
9
  import { RuleBadfilter } from './rule-badfilter.js';
10
10
  import { RulePriority } from './rule-priority.js';
11
11
 
12
+ /**
13
+ * Separator used in network-rule modifier domain lists (`$domain=a|b`).
14
+ */ const DOMAIN_LIST_PIPE_SEPARATOR = '|';
12
15
  /**
13
16
  * Maps canonical content-type modifier names to their DNR `ResourceType`
14
17
  * equivalents. Only modifier names that correspond to adblock filter syntax
@@ -315,6 +318,32 @@ import { RulePriority } from './rule-priority.js';
315
318
  isRequest
316
319
  };
317
320
  }
321
+ /**
322
+ * Parses a pipe-separated domain list, keeping `/regex/` tokens intact
323
+ * (so `|` inside a regexp is not treated as a domain separator).
324
+ *
325
+ * @param value Raw `$domain` / `$to` / `$denyallow` modifier value.
326
+ *
327
+ * @returns Permitted and restricted domain lists.
328
+ */ static parseDomainList(value) {
329
+ const permitted = [];
330
+ const restricted = [];
331
+ const node = DomainListParser.parse(value, undefined, 0, DOMAIN_LIST_PIPE_SEPARATOR);
332
+ for (const { exception, value: domain } of node.children){
333
+ if (!domain) {
334
+ continue;
335
+ }
336
+ if (exception) {
337
+ restricted.push(domain);
338
+ } else {
339
+ permitted.push(domain);
340
+ }
341
+ }
342
+ return {
343
+ permitted,
344
+ restricted
345
+ };
346
+ }
318
347
  /**
319
348
  * Parses the `$header` modifier value into an {@link HttpHeaderMatcher}.
320
349
  *
@@ -496,6 +525,11 @@ import { RulePriority } from './rule-priority.js';
496
525
  */ this.advancedModifierName = null;
497
526
  /**
498
527
  * Raw string value of the advanced modifier.
528
+ *
529
+ * `null` when the modifier has no value. The only exception is
530
+ * `$removeparam`: a value-less `$removeparam` is stored as `''`, because
531
+ * it carries a meaning of its own ("remove all query parameters") that
532
+ * must be distinguishable from "no value".
499
533
  */ this.advancedModifierValue = null;
500
534
  /**
501
535
  * Parsed data for the `$header` modifier.
@@ -538,6 +572,10 @@ import { RulePriority } from './rule-priority.js';
538
572
  const exception = modifier.exception ?? false;
539
573
  const value = modifier.value?.value ?? '';
540
574
  const name = rawName;
575
+ // A noop modifier consists only of underscores and does not affect the rule.
576
+ if (name.startsWith(OPTION_NAMES.NOOP) && !name.split(OPTION_NAMES.NOOP).some((part)=>!!part)) {
577
+ continue;
578
+ }
541
579
  if (exception && !NEGATABLE_MODIFIERS.has(name)) {
542
580
  throw new SyntaxError(`Modifier $${name} cannot be negated`);
543
581
  }
@@ -662,16 +700,7 @@ import { RulePriority } from './rule-priority.js';
662
700
  }
663
701
  case OPTION_NAMES.DOMAIN:
664
702
  {
665
- const parts = value.split('|').filter(Boolean);
666
- const permitted = [];
667
- const restricted = [];
668
- for (const part of parts){
669
- if (part.startsWith('~')) {
670
- restricted.push(part.slice(1));
671
- } else {
672
- permitted.push(part);
673
- }
674
- }
703
+ const { permitted, restricted } = Rule.parseDomainList(value);
675
704
  if (permitted.length > 0) {
676
705
  this.permittedDomains = permitted;
677
706
  meta.permittedDomainCount = permitted.length;
@@ -684,33 +713,24 @@ import { RulePriority } from './rule-priority.js';
684
713
  }
685
714
  case OPTION_NAMES.DENYALLOW:
686
715
  {
687
- const parts = value.split('|').filter(Boolean);
688
- if (parts.some((p)=>p.startsWith('~'))) {
689
- throw new SyntaxError('Modifier $denyallow domains cannot be negated');
716
+ const { permitted, restricted } = Rule.parseDomainList(value);
717
+ if (restricted.length > 0) {
718
+ throw new SyntaxError('modifier $denyallow domains cannot be negated');
690
719
  }
691
- if (parts.length > 0) {
692
- this.denyAllowDomains = parts;
720
+ if (permitted.length > 0) {
721
+ this.denyAllowDomains = permitted;
693
722
  meta.baseModifierCount += 1;
694
723
  }
695
724
  break;
696
725
  }
697
726
  case OPTION_NAMES.TO:
698
727
  {
699
- const parts = value.split('|').filter(Boolean);
700
- const toPermitted = [];
701
- const toRestricted = [];
702
- for (const part of parts){
703
- if (part.startsWith('~')) {
704
- toRestricted.push(part.slice(1));
705
- } else {
706
- toPermitted.push(part);
707
- }
708
- }
709
- if (toPermitted.length > 0) {
710
- this.permittedToDomains = toPermitted;
728
+ const { permitted, restricted } = Rule.parseDomainList(value);
729
+ if (permitted.length > 0) {
730
+ this.permittedToDomains = permitted;
711
731
  }
712
- if (toRestricted.length > 0) {
713
- this.restrictedToDomains = toRestricted;
732
+ if (restricted.length > 0) {
733
+ this.restrictedToDomains = restricted;
714
734
  }
715
735
  meta.baseModifierCount += 1;
716
736
  break;
@@ -746,14 +766,26 @@ import { RulePriority } from './rule-priority.js';
746
766
  this.headerMatcher = Rule.parseHeaderModifier(value);
747
767
  meta.hasHeader = true;
748
768
  break;
749
- case OPTION_NAMES.CSP:
750
769
  case OPTION_NAMES.REMOVEPARAM:
770
+ this.enabledModifiers.add(name);
771
+ this.advancedModifierName = rawName;
772
+ // Keep an empty value as `''` instead of collapsing it to
773
+ // `null`: a value-less `$removeparam` means "remove all
774
+ // query parameters", and the converter relies on this
775
+ // distinction — otherwise such a rule silently degrades
776
+ // into a plain blocking rule.
777
+ // See https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3602.
778
+ this.advancedModifierValue = value;
779
+ break;
780
+ case OPTION_NAMES.CSP:
751
781
  case OPTION_NAMES.COOKIE:
752
782
  case OPTION_NAMES.REPLACE:
753
783
  case OPTION_NAMES.JSONPRUNE:
784
+ case OPTION_NAMES.XMLPRUNE:
754
785
  case OPTION_NAMES.HLS:
755
786
  case OPTION_NAMES.REFERRERPOLICY:
756
787
  case OPTION_NAMES.PERMISSIONS:
788
+ case OPTION_NAMES.URLTRANSFORM:
757
789
  this.enabledModifiers.add(name);
758
790
  this.advancedModifierName = rawName;
759
791
  this.advancedModifierValue = value || null;
@@ -782,8 +814,9 @@ import { RulePriority } from './rule-priority.js';
782
814
  this.advancedModifierValue = value || null;
783
815
  meta.baseModifierCount += 1;
784
816
  break;
785
- // DNS/network-level modifiers — no DNR equivalent.
817
+ // Known unsupported modifiers — no DNR equivalent.
786
818
  // Still added to enabledModifiers so the validator can reject them.
819
+ case OPTION_NAMES.WEBRTC:
787
820
  case OPTION_NAMES.DNSTYPE:
788
821
  case OPTION_NAMES.CTAG:
789
822
  case OPTION_NAMES.CLIENT:
@@ -800,6 +833,16 @@ import { RulePriority } from './rule-priority.js';
800
833
  }
801
834
  this.enabledModifiers.add(OPTION_NAMES.POPUP);
802
835
  break;
836
+ default:
837
+ {
838
+ const modifierView = [
839
+ rawName,
840
+ value
841
+ ].filter((part)=>part).join('=');
842
+ // Unknown modifiers must invalidate the entire rule.
843
+ // RulesScanner catches this error and records it in the conversion result.
844
+ throw new SyntaxError(`Unknown modifier: ${modifierView}`);
845
+ }
803
846
  }
804
847
  }
805
848
  if (this.denyAllowDomains !== null && this.permittedToDomains !== null) {
@@ -1,13 +1,15 @@
1
1
  import { RuleGenerator } from '@adguard/agtree/generator';
2
2
  import { getRedirectFilename } from '@adguard/scriptlets/redirects';
3
- import { MASK_NEGATE_CHARACTER, MASK_REGEX_RULE, CSP_HEADER_NAME, PERMISSIONS_POLICY_HEADER_NAME, MASK_ANY_CHARACTER } from '../constants.js';
3
+ import { MASK_ANY_CHARACTER, MASK_NEGATE_CHARACTER, MASK_REGEX_RULE, CSP_HEADER_NAME, PERMISSIONS_POLICY_HEADER_NAME, DOT } from '../constants.js';
4
+ import { POPULAR_TLDS } from '../constants/popular-tlds.js';
4
5
  import { isConversionError } from '../errors/conversion-errors/index.js';
5
6
  import { ResourcesPathError } from '../errors/converter-options-errors/resources-path-error.js';
6
7
  import { re2Validator } from '../re2-regexp/re2-validator.js';
7
8
  import { OPTION_NAMES } from '../rule/option-names.js';
8
9
  import { RuleDeclarativeValidator } from '../rule/rule-validator.js';
9
10
  import { getErrorMessage } from '../utils/error.js';
10
- import { prepareASCII, removeSlashes, isRegexPattern, toASCII } from '../utils/string.js';
11
+ import { isRegexPattern, toASCII, prepareASCII, removeSlashes } from '../utils/string.js';
12
+ import { UnsupportedModifierError } from '../errors/conversion-errors/unsupported-modifier-error.js';
11
13
  import { HeaderOperation } from '../declarative-rule/modify-header-info.js';
12
14
  import { RuleActionType } from '../declarative-rule/rule-action.js';
13
15
  import { DomainType, ResourceType } from '../declarative-rule/rule-condition.js';
@@ -27,6 +29,54 @@ import { UnsupportedRegexpError } from '../errors/conversion-errors/unsupported-
27
29
  * {@link RegularRuleConverter.convertRule} and {@link RegularRuleConverter.groupConvertedRules}
28
30
  * methods, which contains the general logic of transformation and grouping of rules.
29
31
  */ class RegularRuleConverter {
32
+ /**
33
+ * Checks whether a domain uses wildcard TLD syntax.
34
+ *
35
+ * @param domain Domain to check.
36
+ *
37
+ * @returns True when domain ends with `.*` and has a non-empty prefix.
38
+ */ static isWildcardTldDomain(domain) {
39
+ return domain.length > RegularRuleConverter.WILDCARD_TLD.length && domain.endsWith(RegularRuleConverter.WILDCARD_TLD);
40
+ }
41
+ /**
42
+ * Expands wildcard TLD domain into concrete popular TLD domains.
43
+ *
44
+ * @param domain Wildcard TLD domain.
45
+ *
46
+ * @returns Expanded domain list.
47
+ */ static expandWildcardTldDomain(domain) {
48
+ const domainPrefix = domain.slice(0, -RegularRuleConverter.WILDCARD_TLD.length);
49
+ return POPULAR_TLDS.map((tld)=>`${domainPrefix}.${tld}`);
50
+ }
51
+ /**
52
+ * Prepares domains for DNR condition arrays.
53
+ *
54
+ * Regex and non-TLD wildcard domains are not representable in DNR and are
55
+ * dropped; wildcard TLD domains (e.g. `example.*`) are expanded to the
56
+ * popular TLD list.
57
+ *
58
+ * @param domains Domains from network rule modifier.
59
+ *
60
+ * @returns ASCII-only unique domains supported by DNR.
61
+ */ static prepareDeclarativeDomains(domains) {
62
+ const expandedDomains = domains?.flatMap((domain)=>{
63
+ if (isRegexPattern(domain)) {
64
+ return [];
65
+ }
66
+ if (RegularRuleConverter.isWildcardTldDomain(domain)) {
67
+ return RegularRuleConverter.expandWildcardTldDomain(domain);
68
+ }
69
+ if (domain.includes(MASK_ANY_CHARACTER)) {
70
+ return [];
71
+ }
72
+ return [
73
+ domain
74
+ ];
75
+ }) ?? [];
76
+ return [
77
+ ...new Set(toASCII(expandedDomains))
78
+ ];
79
+ }
30
80
  /**
31
81
  * Checks if {@link Rule} can be converted to {@link RuleActionType.AllowAllRequests}.
32
82
  *
@@ -69,6 +119,9 @@ import { UnsupportedRegexpError } from '../errors/conversion-errors/unsupported-
69
119
  /**
70
120
  * Returns a redirect action for a `$removeparam` rule.
71
121
  *
122
+ * A value-less `$removeparam` (e.g. `||example.org^$removeparam`) removes
123
+ * the whole query string via `transform.query: ''`.
124
+ *
72
125
  * Pipe-separated values (e.g. `utm_source|utm_medium`) are
73
126
  * split into individual `removeParams` entries.
74
127
  *
@@ -78,17 +131,20 @@ import { UnsupportedRegexpError } from '../errors/conversion-errors/unsupported-
78
131
  * @param rule {@link Rule} to get action for.
79
132
  *
80
133
  * @returns Redirect action, or `null` if the rule does not have a
81
- * `$removeparam` modifier, its value is `null`, or a param value cannot be
82
- * URI-decoded (in which case augmentation is skipped).
134
+ * `$removeparam` modifier.
135
+ *
136
+ * @throws {UnsupportedModifierError} If a param value cannot be URI-decoded.
83
137
  */ static getRemoveParamRedirectAction(rule) {
84
138
  if (!rule.isModifierEnabled(OPTION_NAMES.REMOVEPARAM)) {
85
139
  return null;
86
140
  }
87
141
  const value = rule.advancedModifierValue;
88
- if (value === null) {
89
- return null;
90
- }
91
- if (value === '') {
142
+ // Value-less `$removeparam` — remove all query parameters.
143
+ // `Rule` stores such a value as `''`; `null` is not expected here,
144
+ // but is handled the same way defensively: a `$removeparam` rule must
145
+ // never silently degrade into a plain blocking rule.
146
+ // See https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3602.
147
+ if (!value) {
92
148
  return {
93
149
  transform: {
94
150
  query: ''
@@ -97,12 +153,13 @@ import { UnsupportedRegexpError } from '../errors/conversion-errors/unsupported-
97
153
  }
98
154
  // Split on pipe to support multiple param names in a single rule.
99
155
  // If any segment contains invalid percent-encoding, decoding throws;
100
- // skip augmentation by returning null, consistent with getRemoveParamToken().
156
+ // report it as a conversion error so that the rule is skipped instead
157
+ // of being converted into a blocking rule.
101
158
  let removeParams;
102
159
  try {
103
160
  removeParams = value.split(RegularRuleConverter.PIPE_SEPARATOR).map((p)=>decodeURIComponent(p));
104
161
  } catch {
105
- return null;
162
+ throw new UnsupportedModifierError('Network rule with $removeparam modifier contains value that cannot be decoded', rule);
106
163
  }
107
164
  return {
108
165
  transform: {
@@ -262,6 +319,7 @@ import { UnsupportedRegexpError } from '../errors/conversion-errors/unsupported-
262
319
  * @returns The action of a rule that describes what should be done with the request.
263
320
  *
264
321
  * @throws Error {@link ResourcesPathError} when specified an empty path to the web accessible resources.
322
+ * @throws Error {@link UnsupportedModifierError} when a `$removeparam` value cannot be URI-decoded.
265
323
  */ getAction(rule) {
266
324
  if (rule.allowlist) {
267
325
  if (rule.isFilteringDisabled() && RegularRuleConverter.isCompatibleWithAllowAllRequests(rule)) {
@@ -384,28 +442,28 @@ import { UnsupportedRegexpError } from '../errors/conversion-errors/unsupported-
384
442
  condition.domainType = DomainType.FirstParty;
385
443
  }
386
444
  // set `initiatorDomains`
387
- const permittedDomains = rule.permittedDomains?.filter((domain)=>!domain.includes(MASK_ANY_CHARACTER) && !isRegexPattern(domain));
388
- if (permittedDomains && permittedDomains.length > 0) {
389
- condition.initiatorDomains = toASCII(permittedDomains);
445
+ const permittedDomains = RegularRuleConverter.prepareDeclarativeDomains(rule.permittedDomains);
446
+ if (permittedDomains.length > 0) {
447
+ condition.initiatorDomains = permittedDomains;
390
448
  }
391
449
  // set `excludedInitiatorDomains`
392
- const excludedDomains = rule.restrictedDomains;
393
- if (excludedDomains && excludedDomains.length > 0) {
394
- condition.excludedInitiatorDomains = toASCII(excludedDomains);
450
+ const excludedDomains = RegularRuleConverter.prepareDeclarativeDomains(rule.restrictedDomains);
451
+ if (excludedDomains.length > 0) {
452
+ condition.excludedInitiatorDomains = excludedDomains;
395
453
  }
396
454
  // set `requestDomains`
397
- const { permittedToDomains } = rule;
398
- if (permittedToDomains && permittedToDomains.length > 0) {
399
- condition.requestDomains = toASCII(permittedToDomains);
455
+ const permittedToDomains = RegularRuleConverter.prepareDeclarativeDomains(rule.permittedToDomains);
456
+ if (permittedToDomains.length > 0) {
457
+ condition.requestDomains = permittedToDomains;
400
458
  }
401
459
  // Can be specified `$to` or `$denyallow`, but not together.
402
- const { denyAllowDomains } = rule;
403
- const { restrictedToDomains } = rule;
460
+ const denyAllowDomains = RegularRuleConverter.prepareDeclarativeDomains(rule.denyAllowDomains);
461
+ const restrictedToDomains = RegularRuleConverter.prepareDeclarativeDomains(rule.restrictedToDomains);
404
462
  // set `excludedRequestDomains`
405
- if (denyAllowDomains && denyAllowDomains.length !== 0) {
406
- condition.excludedRequestDomains = toASCII(denyAllowDomains);
407
- } else if (restrictedToDomains && restrictedToDomains.length !== 0) {
408
- condition.excludedRequestDomains = toASCII(restrictedToDomains);
463
+ if (denyAllowDomains.length !== 0) {
464
+ condition.excludedRequestDomains = denyAllowDomains;
465
+ } else if (restrictedToDomains.length !== 0) {
466
+ condition.excludedRequestDomains = restrictedToDomains;
409
467
  }
410
468
  // set `excludedResourceTypes`
411
469
  const { restrictedResourceTypes } = rule;
@@ -462,7 +520,7 @@ import { UnsupportedRegexpError } from '../errors/conversion-errors/unsupported-
462
520
  * And if we specify {@link ResourceType.MainFrame}, then we also need to specify all
463
521
  * other types, so that it works not only for document requests, but
464
522
  * also for all other types of requests.
465
- */ const shouldMatchAllResourcesTypes = rule.isModifierEnabled(OPTION_NAMES.REMOVEHEADER) || rule.isModifierEnabled(OPTION_NAMES.CSP) || rule.isModifierEnabled(OPTION_NAMES.COOKIE) || rule.isModifierEnabled(OPTION_NAMES.TO) || rule.isModifierEnabled(OPTION_NAMES.METHOD);
523
+ */ const shouldMatchAllResourcesTypes = rule.isModifierEnabled(OPTION_NAMES.REMOVEHEADER) || rule.isModifierEnabled(OPTION_NAMES.CSP) || rule.isModifierEnabled(OPTION_NAMES.COOKIE) || rule.isModifierEnabled(OPTION_NAMES.TO) || rule.isModifierEnabled(OPTION_NAMES.METHOD) || rule.isModifierEnabled(OPTION_NAMES.URLTRANSFORM);
466
524
  /**
467
525
  * `$permissions` and `$removeparam` modifiers must be applied only to `document` content-type
468
526
  * ({@link ResourceType.MainFrame} and {@link ResourceType.SubFrame}) if they don't have resource types.
@@ -785,5 +843,8 @@ import { UnsupportedRegexpError } from '../errors/conversion-errors/unsupported-
785
843
  * Pipe character used as a separator in $removeparam multi-value rules,
786
844
  * e.g. `$removeparam=utm_source|utm_medium`.
787
845
  */ RegularRuleConverter.PIPE_SEPARATOR = '|';
846
+ /**
847
+ * Wildcard TLD suffix (`.*`) used in domain modifiers, e.g. `example.*`.
848
+ */ RegularRuleConverter.WILDCARD_TLD = `${DOT}${MASK_ANY_CHARACTER}`;
788
849
 
789
850
  export { RegularRuleConverter };
@@ -99,6 +99,11 @@ declare class Rule {
99
99
  readonly advancedModifierName: string | null;
100
100
  /**
101
101
  * Raw string value of the advanced modifier.
102
+ *
103
+ * `null` when the modifier has no value. The only exception is
104
+ * `$removeparam`: a value-less `$removeparam` is stored as `''`, because
105
+ * it carries a meaning of its own ("remove all query parameters") that
106
+ * must be distinguishable from "no value".
102
107
  */
103
108
  readonly advancedModifierValue: string | null;
104
109
  /**
@@ -217,6 +222,15 @@ declare class Rule {
217
222
  * headers.
218
223
  */
219
224
  private static computeRemoveHeaderInfo;
225
+ /**
226
+ * Parses a pipe-separated domain list, keeping `/regex/` tokens intact
227
+ * (so `|` inside a regexp is not treated as a domain separator).
228
+ *
229
+ * @param value Raw `$domain` / `$to` / `$denyallow` modifier value.
230
+ *
231
+ * @returns Permitted and restricted domain lists.
232
+ */
233
+ private static parseDomainList;
220
234
  /**
221
235
  * Parses the `$header` modifier value into an {@link HttpHeaderMatcher}.
222
236
  *