@adguard/dnr-converter 1.1.2 → 2.0.0-beta.0
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.
- package/LICENSE +674 -0
- package/README.md +75 -5
- package/dist/cli.cjs +694 -179
- package/dist/errors/metadata-errors/invalid-metadata-chunks-error.js +23 -0
- package/dist/index.js +2 -0
- package/dist/package.json.js +144 -2
- package/dist/ruleset/compact-ruleset.js +32 -0
- package/dist/ruleset/metadata-chunks.js +178 -0
- package/dist/ruleset/metadata-rule.js +100 -28
- package/dist/ruleset/metadata-ruleset.js +23 -31
- package/dist/ruleset/ruleset-with-source-map.js +135 -46
- package/dist/types/src/errors/metadata-errors/invalid-metadata-chunks-error.d.ts +21 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/ruleset/compact-ruleset.d.ts +52 -0
- package/dist/types/src/ruleset/metadata-ruleset.d.ts +10 -6
- package/dist/types/src/ruleset/ruleset-with-source-map.d.ts +120 -3
- package/dist/types/src/version.d.ts +6 -0
- package/dist/utils/string.js +1 -1
- package/dist/version.js +11 -2
- package/package.json +8 -10
package/dist/cli.cjs
CHANGED
|
@@ -30,11 +30,162 @@ function _interopNamespaceDefault(e) {
|
|
|
30
30
|
|
|
31
31
|
var v__namespace = /*#__PURE__*/_interopNamespaceDefault(v);
|
|
32
32
|
|
|
33
|
-
var
|
|
33
|
+
var name = "@adguard/dnr-converter";
|
|
34
|
+
var description = "A converter that transforms adblock-style filtering rules into rules compatible with the Declarative Net Request (DNR) API.";
|
|
35
|
+
var main$1 = "dist/index.js";
|
|
36
|
+
var module$1 = "dist/index.js";
|
|
37
|
+
var types = "dist/types/src/index.d.ts";
|
|
38
|
+
var type$1 = "module";
|
|
39
|
+
var sideEffects = false;
|
|
40
|
+
var files = [
|
|
41
|
+
"dist"
|
|
42
|
+
];
|
|
43
|
+
var exports$1 = {
|
|
44
|
+
".": {
|
|
45
|
+
"import": "./dist/index.js",
|
|
46
|
+
types: "./dist/types/src/index.d.ts"
|
|
47
|
+
},
|
|
48
|
+
"./cli": {
|
|
49
|
+
types: "./dist/types/cli/index.d.ts",
|
|
50
|
+
"default": "./dist/cli.cjs"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var bin = {
|
|
54
|
+
"dnr-converter": "dist/cli.cjs"
|
|
55
|
+
};
|
|
56
|
+
var typesVersions = {
|
|
57
|
+
"*": {
|
|
58
|
+
"*": [
|
|
59
|
+
"dist/types/src/index.d.ts"
|
|
60
|
+
],
|
|
61
|
+
cli: [
|
|
62
|
+
"dist/types/cli/index.d.ts"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var author = "Adguard Software Ltd.";
|
|
67
|
+
var repository = {
|
|
68
|
+
type: "git",
|
|
69
|
+
url: "git+https://github.com/AdGuardSoftwareLimited/ext-tsurlfilter.git",
|
|
70
|
+
directory: "packages/dnr-converter"
|
|
71
|
+
};
|
|
72
|
+
var license = "GPL-3.0-only";
|
|
73
|
+
var engines = {
|
|
74
|
+
node: ">=22"
|
|
75
|
+
};
|
|
76
|
+
var bugs = {
|
|
77
|
+
url: "https://github.com/AdguardTeam/tsurlfilter/issues"
|
|
78
|
+
};
|
|
79
|
+
var homepage = "https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/dnr-converter#readme";
|
|
80
|
+
var scripts = {
|
|
81
|
+
lint: "pnpm lint:code && pnpm lint:types && pnpm lint:md",
|
|
82
|
+
"lint:code": "eslint --cache --ignore-path .gitignore .",
|
|
83
|
+
"lint:types": "tsc",
|
|
84
|
+
"lint:md": "markdownlint .",
|
|
85
|
+
start: "rollup -c rollup.config.ts --configPlugin typescript -w",
|
|
86
|
+
build: "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
|
87
|
+
"docs:examples": "tsx tasks/generate-examples.ts",
|
|
88
|
+
test: "vitest run",
|
|
89
|
+
"test:light": "vitest run --exclude \"**/*benchmark*.test.ts\"",
|
|
90
|
+
"test:watch": "vitest run --watch",
|
|
91
|
+
"test:ci": "vitest run --no-cache --reporter default --reporter junit --outputFile=./tests-reports/dnr-converter.xml",
|
|
92
|
+
"test:coverage": "vitest run --coverage",
|
|
93
|
+
"test:smoke": "(cd test/smoke/esm && pnpm test) && (cd test/smoke/exports && pnpm test)",
|
|
94
|
+
"test:prod": "pnpm lint && pnpm test:smoke && pnpm test -- --no-cache",
|
|
95
|
+
"test:debug": "vitest run --inspect --no-file-parallelism --watch",
|
|
96
|
+
precommit: "lint-staged",
|
|
97
|
+
prepublishOnly: "pnpm build",
|
|
98
|
+
tgz: "pnpm pack --out dnr-converter.tgz"
|
|
99
|
+
};
|
|
100
|
+
var peerDependencies = {
|
|
101
|
+
"@adguard/re2-wasm": "1.2.0"
|
|
102
|
+
};
|
|
103
|
+
var dependencies = {
|
|
104
|
+
"@adguard/agtree": "workspace:^",
|
|
105
|
+
"@adguard/logger": "workspace:^",
|
|
106
|
+
"@adguard/scriptlets": "catalog:",
|
|
107
|
+
commander: "catalog:",
|
|
108
|
+
punycode: "catalog:",
|
|
109
|
+
valibot: "catalog:"
|
|
110
|
+
};
|
|
111
|
+
var devDependencies = {
|
|
112
|
+
"@adguard/eslint-plugin-logger-context": "workspace:^",
|
|
113
|
+
"@adguard/tsurlfilter": "workspace:^",
|
|
114
|
+
"@rollup/plugin-commonjs": "catalog:",
|
|
115
|
+
"@rollup/plugin-json": "catalog:",
|
|
116
|
+
"@rollup/plugin-node-resolve": "catalog:",
|
|
117
|
+
"@rollup/plugin-swc": "catalog:",
|
|
118
|
+
"@rollup/plugin-typescript": "catalog:",
|
|
119
|
+
"@types/chrome": "catalog:",
|
|
120
|
+
"@types/node": "catalog:",
|
|
121
|
+
"@types/punycode": "catalog:",
|
|
122
|
+
"@typescript-eslint/eslint-plugin": "catalog:",
|
|
123
|
+
"@typescript-eslint/parser": "catalog:",
|
|
124
|
+
"@vitest/coverage-v8": "catalog:",
|
|
125
|
+
eslint: "catalog:",
|
|
126
|
+
"eslint-config-airbnb-base": "catalog:",
|
|
127
|
+
"eslint-config-airbnb-typescript": "catalog:",
|
|
128
|
+
"eslint-plugin-boundaries": "catalog:",
|
|
129
|
+
"eslint-plugin-import": "catalog:",
|
|
130
|
+
"eslint-plugin-import-newlines": "catalog:",
|
|
131
|
+
"eslint-plugin-jsdoc": "catalog:",
|
|
132
|
+
"eslint-plugin-n": "catalog:",
|
|
133
|
+
"lint-staged": "catalog:",
|
|
134
|
+
markdownlint: "catalog:",
|
|
135
|
+
"markdownlint-cli": "catalog:",
|
|
136
|
+
rimraf: "catalog:",
|
|
137
|
+
rollup: "catalog:",
|
|
138
|
+
"rollup-plugin-copy": "catalog:",
|
|
139
|
+
"rollup-plugin-dts": "catalog:",
|
|
140
|
+
"rollup-plugin-node-externals": "catalog:",
|
|
141
|
+
tsd: "catalog:",
|
|
142
|
+
tsx: "catalog:",
|
|
143
|
+
typescript: "catalog:",
|
|
144
|
+
vitest: "catalog:"
|
|
145
|
+
};
|
|
146
|
+
var version = "2.0.0-beta.0";
|
|
147
|
+
var packageJson = {
|
|
148
|
+
name: name,
|
|
149
|
+
description: description,
|
|
150
|
+
main: main$1,
|
|
151
|
+
module: module$1,
|
|
152
|
+
types: types,
|
|
153
|
+
type: type$1,
|
|
154
|
+
sideEffects: sideEffects,
|
|
155
|
+
files: files,
|
|
156
|
+
exports: exports$1,
|
|
157
|
+
bin: bin,
|
|
158
|
+
typesVersions: typesVersions,
|
|
159
|
+
author: author,
|
|
160
|
+
repository: repository,
|
|
161
|
+
license: license,
|
|
162
|
+
engines: engines,
|
|
163
|
+
bugs: bugs,
|
|
164
|
+
homepage: homepage,
|
|
165
|
+
scripts: scripts,
|
|
166
|
+
"lint-staged": {
|
|
167
|
+
"{src,cli,test,tasks}/**/*.ts": [
|
|
168
|
+
"eslint"
|
|
169
|
+
]
|
|
170
|
+
},
|
|
171
|
+
peerDependencies: peerDependencies,
|
|
172
|
+
dependencies: dependencies,
|
|
173
|
+
devDependencies: devDependencies,
|
|
174
|
+
version: version
|
|
175
|
+
};
|
|
34
176
|
|
|
177
|
+
if (!('version' in packageJson) || "string" !== 'string' || packageJson.version.length === 0) {
|
|
178
|
+
throw new Error('Package version is missing. Run scripts/inject-package-versions.mjs before building.');
|
|
179
|
+
}
|
|
35
180
|
/**
|
|
36
181
|
* Version of the `@adguard/dnr-converter` package.
|
|
37
|
-
|
|
182
|
+
*
|
|
183
|
+
* Annotated as `string` (not inferred from `packageJson.version`) because the
|
|
184
|
+
* committed manifest is versionless: before injection TypeScript narrows
|
|
185
|
+
* `packageJson.version` to `never`, which would leak an unstable `never` type
|
|
186
|
+
* into the public API (`never` is assignable to `string`, and the runtime guard
|
|
187
|
+
* above still enforces non-emptyness in both states).
|
|
188
|
+
*/ const DNR_CONVERTER_VERSION = packageJson.version;
|
|
38
189
|
|
|
39
190
|
/**
|
|
40
191
|
* Describes error when maximum number of rules is equal or less than `0`.
|
|
@@ -656,7 +807,7 @@ var version = "1.1.2";
|
|
|
656
807
|
});
|
|
657
808
|
|
|
658
809
|
/*
|
|
659
|
-
* AGTree v4.2.1 (build date:
|
|
810
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
660
811
|
* (c) 2026 Adguard Software Ltd.
|
|
661
812
|
* Released under the MIT license
|
|
662
813
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -682,7 +833,7 @@ var version = "1.1.2";
|
|
|
682
833
|
}
|
|
683
834
|
|
|
684
835
|
/*
|
|
685
|
-
* AGTree v4.2.1 (build date:
|
|
836
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
686
837
|
* (c) 2026 Adguard Software Ltd.
|
|
687
838
|
* Released under the MIT license
|
|
688
839
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -804,7 +955,7 @@ var version = "1.1.2";
|
|
|
804
955
|
};
|
|
805
956
|
|
|
806
957
|
/*
|
|
807
|
-
* AGTree v4.2.1 (build date:
|
|
958
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
808
959
|
* (c) 2026 Adguard Software Ltd.
|
|
809
960
|
* Released under the MIT license
|
|
810
961
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -874,7 +1025,7 @@ var version = "1.1.2";
|
|
|
874
1025
|
};
|
|
875
1026
|
|
|
876
1027
|
/*
|
|
877
|
-
* AGTree v4.2.1 (build date:
|
|
1028
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
878
1029
|
* (c) 2026 Adguard Software Ltd.
|
|
879
1030
|
* Released under the MIT license
|
|
880
1031
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -916,7 +1067,7 @@ const BASE_MESSAGE = 'Not implemented';
|
|
|
916
1067
|
}
|
|
917
1068
|
|
|
918
1069
|
/*
|
|
919
|
-
* AGTree v4.2.1 (build date:
|
|
1070
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
920
1071
|
* (c) 2026 Adguard Software Ltd.
|
|
921
1072
|
* Released under the MIT license
|
|
922
1073
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -936,7 +1087,7 @@ const BASE_MESSAGE = 'Not implemented';
|
|
|
936
1087
|
});
|
|
937
1088
|
|
|
938
1089
|
/*
|
|
939
|
-
* AGTree v4.2.1 (build date:
|
|
1090
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
940
1091
|
* (c) 2026 Adguard Software Ltd.
|
|
941
1092
|
* Released under the MIT license
|
|
942
1093
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -947,7 +1098,7 @@ const BASE_MESSAGE = 'Not implemented';
|
|
|
947
1098
|
/**
|
|
948
1099
|
* Empty string.
|
|
949
1100
|
*/ const EMPTY = '';
|
|
950
|
-
const SPACE = ' ';
|
|
1101
|
+
const SPACE$1 = ' ';
|
|
951
1102
|
const TAB$1 = '\t';
|
|
952
1103
|
const COLON = ':';
|
|
953
1104
|
const COMMA = ',';
|
|
@@ -969,8 +1120,8 @@ const SLASH = '/';
|
|
|
969
1120
|
const TILDE = '~';
|
|
970
1121
|
const UNDERSCORE = '_';
|
|
971
1122
|
// Escape characters
|
|
972
|
-
const BACKSLASH = '\\';
|
|
973
|
-
const ESCAPE_CHARACTER = BACKSLASH;
|
|
1123
|
+
const BACKSLASH$1 = '\\';
|
|
1124
|
+
const ESCAPE_CHARACTER = BACKSLASH$1;
|
|
974
1125
|
// Newlines
|
|
975
1126
|
const CR = '\r';
|
|
976
1127
|
const FF = '\f';
|
|
@@ -1096,7 +1247,7 @@ const INCLUDE = 'include';
|
|
|
1096
1247
|
}
|
|
1097
1248
|
for(let i = 0; i < rule.length; i += 1){
|
|
1098
1249
|
if (rule[i] === '#') {
|
|
1099
|
-
if (rule[i + 1] === '#' && rule[i - 1] !== SPACE) {
|
|
1250
|
+
if (rule[i + 1] === '#' && rule[i - 1] !== SPACE$1) {
|
|
1100
1251
|
// ##
|
|
1101
1252
|
return createResult(i, CosmeticRuleSeparator.ElementHiding);
|
|
1102
1253
|
}
|
|
@@ -1120,7 +1271,7 @@ const INCLUDE = 'include';
|
|
|
1120
1271
|
}
|
|
1121
1272
|
// Exceptions
|
|
1122
1273
|
if (rule[i + 1] === '@') {
|
|
1123
|
-
if (rule[i + 2] === '#' && rule[i - 1] !== SPACE) {
|
|
1274
|
+
if (rule[i + 2] === '#' && rule[i - 1] !== SPACE$1) {
|
|
1124
1275
|
// #@#
|
|
1125
1276
|
return createResult(i, CosmeticRuleSeparator.ElementHidingException);
|
|
1126
1277
|
}
|
|
@@ -1458,7 +1609,7 @@ const DOUBLE_QUOTE_MARKER = '"';
|
|
|
1458
1609
|
*
|
|
1459
1610
|
* @returns True if the given character is a space or tab character, false otherwise.
|
|
1460
1611
|
*/ static isWhitespace(char) {
|
|
1461
|
-
return char === SPACE || char === TAB$1;
|
|
1612
|
+
return char === SPACE$1 || char === TAB$1;
|
|
1462
1613
|
}
|
|
1463
1614
|
/**
|
|
1464
1615
|
* Checks if the given character is a digit.
|
|
@@ -1731,7 +1882,7 @@ const DOUBLE_QUOTE_MARKER = '"';
|
|
|
1731
1882
|
}
|
|
1732
1883
|
|
|
1733
1884
|
/*
|
|
1734
|
-
* AGTree v4.2.1 (build date:
|
|
1885
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
1735
1886
|
* (c) 2026 Adguard Software Ltd.
|
|
1736
1887
|
* Released under the MIT license
|
|
1737
1888
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -3379,7 +3530,7 @@ var lib = JSON5;
|
|
|
3379
3530
|
const char = raw[offset];
|
|
3380
3531
|
// Abort consuming the hint name if we encounter a whitespace character
|
|
3381
3532
|
// or an opening parenthesis, which means 'HIT_NAME(' case
|
|
3382
|
-
if (char === OPEN_PARENTHESIS || char === SPACE) {
|
|
3533
|
+
if (char === OPEN_PARENTHESIS || char === SPACE$1) {
|
|
3383
3534
|
break;
|
|
3384
3535
|
}
|
|
3385
3536
|
// Hint name should only contain letters, digits, and underscores
|
|
@@ -3511,13 +3662,13 @@ var lib = JSON5;
|
|
|
3511
3662
|
let hintEndIndex = offset;
|
|
3512
3663
|
let balance = 0;
|
|
3513
3664
|
while(hintEndIndex < raw.length){
|
|
3514
|
-
if (raw[hintEndIndex] === OPEN_PARENTHESIS && raw[hintEndIndex - 1] !== BACKSLASH) {
|
|
3665
|
+
if (raw[hintEndIndex] === OPEN_PARENTHESIS && raw[hintEndIndex - 1] !== BACKSLASH$1) {
|
|
3515
3666
|
balance += 1;
|
|
3516
3667
|
// Throw error for nesting
|
|
3517
3668
|
if (balance > 1) {
|
|
3518
3669
|
throw new AdblockSyntaxError('Invalid hint: nested parentheses are not allowed', baseOffset + hintStartIndex, baseOffset + hintEndIndex);
|
|
3519
3670
|
}
|
|
3520
|
-
} else if (raw[hintEndIndex] === CLOSE_PARENTHESIS && raw[hintEndIndex - 1] !== BACKSLASH) {
|
|
3671
|
+
} else if (raw[hintEndIndex] === CLOSE_PARENTHESIS && raw[hintEndIndex - 1] !== BACKSLASH$1) {
|
|
3521
3672
|
balance -= 1;
|
|
3522
3673
|
} else if (StringUtils.isWhitespace(raw[hintEndIndex]) && balance === 0) {
|
|
3523
3674
|
break;
|
|
@@ -4479,7 +4630,7 @@ function requireSprintf () {
|
|
|
4479
4630
|
var sprintfExports = requireSprintf();
|
|
4480
4631
|
|
|
4481
4632
|
/*
|
|
4482
|
-
* CSSTokenizer v1.2.0 (build date:
|
|
4633
|
+
* CSSTokenizer v1.2.0 (build date: Mon, 28 Sep 2026 19:57:01 GMT)
|
|
4483
4634
|
* (c) 2026 Adguard Software Ltd.
|
|
4484
4635
|
* Released under the MIT license
|
|
4485
4636
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/css-tokenizer#readme
|
|
@@ -6076,7 +6227,7 @@ const XPATH_HASH = 196571984; // getStringHash('xpath')
|
|
|
6076
6227
|
};
|
|
6077
6228
|
|
|
6078
6229
|
/*
|
|
6079
|
-
* AGTree v4.2.1 (build date:
|
|
6230
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
6080
6231
|
* (c) 2026 Adguard Software Ltd.
|
|
6081
6232
|
* Released under the MIT license
|
|
6082
6233
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -6090,7 +6241,7 @@ const XPATH_HASH = 196571984; // getStringHash('xpath')
|
|
|
6090
6241
|
};
|
|
6091
6242
|
|
|
6092
6243
|
/*
|
|
6093
|
-
* AGTree v4.2.1 (build date:
|
|
6244
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
6094
6245
|
* (c) 2026 Adguard Software Ltd.
|
|
6095
6246
|
* Released under the MIT license
|
|
6096
6247
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -6181,7 +6332,7 @@ const XPATH_HASH = 196571984; // getStringHash('xpath')
|
|
|
6181
6332
|
*/ const REMOVE_VALUE = 'true';
|
|
6182
6333
|
|
|
6183
6334
|
/*
|
|
6184
|
-
* AGTree v4.2.1 (build date:
|
|
6335
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
6185
6336
|
* (c) 2026 Adguard Software Ltd.
|
|
6186
6337
|
* Released under the MIT license
|
|
6187
6338
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -7703,7 +7854,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
7703
7854
|
*
|
|
7704
7855
|
* @example
|
|
7705
7856
|
* ['abc', 'def']: strings[] -> "'abc', 'def'": string
|
|
7706
|
-
*/ static quoteAndJoinStrings(strings, quoteType = QuoteType.Single, separator = `${COMMA}${SPACE}`) {
|
|
7857
|
+
*/ static quoteAndJoinStrings(strings, quoteType = QuoteType.Single, separator = `${COMMA}${SPACE$1}`) {
|
|
7707
7858
|
return strings.map((s)=>QuoteUtils.setStringQuoteType(s, quoteType)).join(separator);
|
|
7708
7859
|
}
|
|
7709
7860
|
/**
|
|
@@ -8115,7 +8266,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
8115
8266
|
throw new AdblockSyntaxError(sprintfExports.sprintf("Unexpected token '%s' with value '%s'", getFormattedTokenName(token.type), raw.slice(token.start, token.end)), baseOffset + token.start, baseOffset + token.end);
|
|
8116
8267
|
}
|
|
8117
8268
|
// Handle edge case for descendant combinator
|
|
8118
|
-
if (combinator === SPACE) {
|
|
8269
|
+
if (combinator === SPACE$1) {
|
|
8119
8270
|
// Skip whitespaces before checking next token
|
|
8120
8271
|
stream.skipWhitespace();
|
|
8121
8272
|
// EOF - just skip, we shouldn't consider it as descendant combinator
|
|
@@ -8223,7 +8374,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
8223
8374
|
}
|
|
8224
8375
|
|
|
8225
8376
|
/*
|
|
8226
|
-
* AGTree v4.2.1 (build date:
|
|
8377
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
8227
8378
|
* (c) 2026 Adguard Software Ltd.
|
|
8228
8379
|
* Released under the MIT license
|
|
8229
8380
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -8544,7 +8695,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
8544
8695
|
// End of current compound selector (whitespace combinator - descendant)
|
|
8545
8696
|
case TokenType.Whitespace:
|
|
8546
8697
|
{
|
|
8547
|
-
CompoundSelectorHandler.handle(context, SPACE);
|
|
8698
|
+
CompoundSelectorHandler.handle(context, SPACE$1);
|
|
8548
8699
|
break;
|
|
8549
8700
|
}
|
|
8550
8701
|
// End of current complex selector
|
|
@@ -8832,7 +8983,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
8832
8983
|
}
|
|
8833
8984
|
|
|
8834
8985
|
/*
|
|
8835
|
-
* AGTree v4.2.1 (build date:
|
|
8986
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
8836
8987
|
* (c) 2026 Adguard Software Ltd.
|
|
8837
8988
|
* Released under the MIT license
|
|
8838
8989
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -8900,7 +9051,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
8900
9051
|
semicolonIndex = raw.length;
|
|
8901
9052
|
}
|
|
8902
9053
|
const scriptletCallEnd = Math.max(StringUtils.skipWSBack(raw, semicolonIndex - 1) + 1, scriptletCallStart);
|
|
8903
|
-
const params = ParameterListParser.parse(raw.slice(scriptletCallStart, scriptletCallEnd), options, baseOffset + scriptletCallStart, SPACE);
|
|
9054
|
+
const params = ParameterListParser.parse(raw.slice(scriptletCallStart, scriptletCallEnd), options, baseOffset + scriptletCallStart, SPACE$1);
|
|
8904
9055
|
// Parse the scriptlet call
|
|
8905
9056
|
result.children.push(params);
|
|
8906
9057
|
// Skip the semicolon
|
|
@@ -8953,7 +9104,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
8953
9104
|
}
|
|
8954
9105
|
offset += ADG_SCRIPTLET_MASK.length;
|
|
8955
9106
|
// Whitespace is not allowed after the mask
|
|
8956
|
-
if (raw[offset] === SPACE) {
|
|
9107
|
+
if (raw[offset] === SPACE$1) {
|
|
8957
9108
|
throw new AdblockSyntaxError(this.ERROR_MESSAGES.WHITESPACE_AFTER_MASK, baseOffset + offset, baseOffset + raw.length);
|
|
8958
9109
|
}
|
|
8959
9110
|
// Parameter list should be wrapped in parentheses
|
|
@@ -9212,7 +9363,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
9212
9363
|
}
|
|
9213
9364
|
offset += scriptletMaskLength;
|
|
9214
9365
|
// Whitespace is not allowed after the mask
|
|
9215
|
-
if (raw[offset] === SPACE) {
|
|
9366
|
+
if (raw[offset] === SPACE$1) {
|
|
9216
9367
|
throw new AdblockSyntaxError(this.ERROR_MESSAGES.WHITESPACE_AFTER_MASK, baseOffset + offset, baseOffset + raw.length);
|
|
9217
9368
|
}
|
|
9218
9369
|
// Parameter list should be wrapped in parentheses
|
|
@@ -22728,7 +22879,7 @@ function getDomain(url, options = {}) {
|
|
|
22728
22879
|
// Agent adblock version (if present)
|
|
22729
22880
|
if (!isUndefined(value.version)) {
|
|
22730
22881
|
// Add a space between the name and the version
|
|
22731
|
-
result += SPACE;
|
|
22882
|
+
result += SPACE$1;
|
|
22732
22883
|
result += value.version.value;
|
|
22733
22884
|
}
|
|
22734
22885
|
return result;
|
|
@@ -22746,7 +22897,7 @@ function getDomain(url, options = {}) {
|
|
|
22746
22897
|
* @returns Raw string.
|
|
22747
22898
|
*/ static generate(ast) {
|
|
22748
22899
|
let result = OPEN_SQUARE_BRACKET;
|
|
22749
|
-
result += ast.children.map(AgentGenerator.generate).join(SEMICOLON + SPACE);
|
|
22900
|
+
result += ast.children.map(AgentGenerator.generate).join(SEMICOLON + SPACE$1);
|
|
22750
22901
|
result += CLOSE_SQUARE_BRACKET;
|
|
22751
22902
|
return result;
|
|
22752
22903
|
}
|
|
@@ -22791,12 +22942,12 @@ function getDomain(url, options = {}) {
|
|
|
22791
22942
|
let result = EMPTY;
|
|
22792
22943
|
// if allowSpace is true, join with a single separator
|
|
22793
22944
|
// without space
|
|
22794
|
-
if (!allowSpace && separator !== SPACE) {
|
|
22945
|
+
if (!allowSpace && separator !== SPACE$1) {
|
|
22795
22946
|
result = collection.join(separator);
|
|
22796
22947
|
} else {
|
|
22797
22948
|
// join parameters with separator
|
|
22798
22949
|
// if the separator is a space, join with a single space
|
|
22799
|
-
result = collection.join(separator === SPACE ? separator : `${separator}${SPACE}`);
|
|
22950
|
+
result = collection.join(separator === SPACE$1 ? separator : `${separator}${SPACE$1}`);
|
|
22800
22951
|
}
|
|
22801
22952
|
return result;
|
|
22802
22953
|
}
|
|
@@ -22814,10 +22965,10 @@ function getDomain(url, options = {}) {
|
|
|
22814
22965
|
*/ static generate(node) {
|
|
22815
22966
|
let result = EMPTY;
|
|
22816
22967
|
result += node.marker.value;
|
|
22817
|
-
result += SPACE;
|
|
22968
|
+
result += SPACE$1;
|
|
22818
22969
|
result += node.command.value;
|
|
22819
22970
|
if (node.params) {
|
|
22820
|
-
result += SPACE;
|
|
22971
|
+
result += SPACE$1;
|
|
22821
22972
|
if (node.params.type === 'ParameterList') {
|
|
22822
22973
|
result += ParameterListGenerator.generate(node.params, COMMA);
|
|
22823
22974
|
} else {
|
|
@@ -22827,7 +22978,7 @@ function getDomain(url, options = {}) {
|
|
|
22827
22978
|
}
|
|
22828
22979
|
// Add comment within the config comment
|
|
22829
22980
|
if (node.comment) {
|
|
22830
|
-
result += SPACE;
|
|
22981
|
+
result += SPACE$1;
|
|
22831
22982
|
result += node.comment.value;
|
|
22832
22983
|
}
|
|
22833
22984
|
return result;
|
|
@@ -22865,8 +23016,8 @@ function getDomain(url, options = {}) {
|
|
|
22865
23016
|
*
|
|
22866
23017
|
* @returns Raw string.
|
|
22867
23018
|
*/ static generate(node) {
|
|
22868
|
-
let result = HINT_MARKER + SPACE;
|
|
22869
|
-
result += node.children.map(HintGenerator.generate).join(SPACE);
|
|
23019
|
+
let result = HINT_MARKER + SPACE$1;
|
|
23020
|
+
result += node.children.map(HintGenerator.generate).join(SPACE$1);
|
|
22870
23021
|
return result;
|
|
22871
23022
|
}
|
|
22872
23023
|
}
|
|
@@ -22883,10 +23034,10 @@ function getDomain(url, options = {}) {
|
|
|
22883
23034
|
*/ static generate(node) {
|
|
22884
23035
|
let result = EMPTY;
|
|
22885
23036
|
result += ValueGenerator.generate(node.marker);
|
|
22886
|
-
result += SPACE;
|
|
23037
|
+
result += SPACE$1;
|
|
22887
23038
|
result += ValueGenerator.generate(node.header);
|
|
22888
23039
|
result += COLON;
|
|
22889
|
-
result += SPACE;
|
|
23040
|
+
result += SPACE$1;
|
|
22890
23041
|
result += ValueGenerator.generate(node.value);
|
|
22891
23042
|
return result;
|
|
22892
23043
|
}
|
|
@@ -22949,7 +23100,7 @@ function getDomain(url, options = {}) {
|
|
|
22949
23100
|
}
|
|
22950
23101
|
// Space is not allowed after "safari_cb_affinity" directive, so we need to handle it separately.
|
|
22951
23102
|
if (node.name.value !== SAFARI_CB_AFFINITY) {
|
|
22952
|
-
result += SPACE;
|
|
23103
|
+
result += SPACE$1;
|
|
22953
23104
|
}
|
|
22954
23105
|
if (node.params.type === 'Value') {
|
|
22955
23106
|
result += ValueGenerator.generate(node.params);
|
|
@@ -23023,17 +23174,17 @@ function getDomain(url, options = {}) {
|
|
|
23023
23174
|
*/ static generate(node) {
|
|
23024
23175
|
const result = [];
|
|
23025
23176
|
if (node.mediaQueryList) {
|
|
23026
|
-
result.push(CSS_MEDIA_MARKER, SPACE, node.mediaQueryList.value, SPACE, OPEN_CURLY_BRACKET, SPACE);
|
|
23177
|
+
result.push(CSS_MEDIA_MARKER, SPACE$1, node.mediaQueryList.value, SPACE$1, OPEN_CURLY_BRACKET, SPACE$1);
|
|
23027
23178
|
}
|
|
23028
|
-
result.push(node.selectorList.value, SPACE, OPEN_CURLY_BRACKET, SPACE);
|
|
23179
|
+
result.push(node.selectorList.value, SPACE$1, OPEN_CURLY_BRACKET, SPACE$1);
|
|
23029
23180
|
if (node.remove) {
|
|
23030
23181
|
result.push(AdgCssInjectionGenerator.REMOVE_DECLARATION);
|
|
23031
23182
|
} else if (node.declarationList?.value) {
|
|
23032
23183
|
result.push(node.declarationList.value);
|
|
23033
23184
|
}
|
|
23034
|
-
result.push(SPACE, CLOSE_CURLY_BRACKET);
|
|
23185
|
+
result.push(SPACE$1, CLOSE_CURLY_BRACKET);
|
|
23035
23186
|
if (node.mediaQueryList) {
|
|
23036
|
-
result.push(SPACE, CLOSE_CURLY_BRACKET);
|
|
23187
|
+
result.push(SPACE$1, CLOSE_CURLY_BRACKET);
|
|
23037
23188
|
}
|
|
23038
23189
|
return result.join(EMPTY);
|
|
23039
23190
|
}
|
|
@@ -23061,7 +23212,7 @@ function getDomain(url, options = {}) {
|
|
|
23061
23212
|
const quotedValue = QuoteUtils.setStringQuoteType(generatedValue, QuoteType.Double);
|
|
23062
23213
|
result.push(quotedValue);
|
|
23063
23214
|
if (node.flag) {
|
|
23064
|
-
result.push(SPACE);
|
|
23215
|
+
result.push(SPACE$1);
|
|
23065
23216
|
result.push(ValueGenerator.generate(node.flag));
|
|
23066
23217
|
}
|
|
23067
23218
|
}
|
|
@@ -23134,7 +23285,7 @@ function getDomain(url, options = {}) {
|
|
|
23134
23285
|
if (node.value === ' ') {
|
|
23135
23286
|
return node.value;
|
|
23136
23287
|
}
|
|
23137
|
-
return SPACE + node.value + SPACE;
|
|
23288
|
+
return SPACE$1 + node.value + SPACE$1;
|
|
23138
23289
|
}
|
|
23139
23290
|
}
|
|
23140
23291
|
|
|
@@ -23224,7 +23375,7 @@ function getDomain(url, options = {}) {
|
|
|
23224
23375
|
const complexSelector = node.children[i];
|
|
23225
23376
|
if (i > 0) {
|
|
23226
23377
|
result.push(COMMA);
|
|
23227
|
-
result.push(SPACE);
|
|
23378
|
+
result.push(SPACE$1);
|
|
23228
23379
|
}
|
|
23229
23380
|
result.push(ComplexSelectorGenerator.generate(complexSelector));
|
|
23230
23381
|
}
|
|
@@ -23362,9 +23513,9 @@ function getDomain(url, options = {}) {
|
|
|
23362
23513
|
if (scriptletCall.children.length === 0) {
|
|
23363
23514
|
throw new Error(AbpSnippetInjectionBodyCommon.ERROR_MESSAGES.EMPTY_SCRIPTLET_CALL);
|
|
23364
23515
|
}
|
|
23365
|
-
result.push(ParameterListGenerator.generate(scriptletCall, SPACE));
|
|
23516
|
+
result.push(ParameterListGenerator.generate(scriptletCall, SPACE$1));
|
|
23366
23517
|
}
|
|
23367
|
-
return result.join(SEMICOLON + SPACE);
|
|
23518
|
+
return result.join(SEMICOLON + SPACE$1);
|
|
23368
23519
|
}
|
|
23369
23520
|
}
|
|
23370
23521
|
|
|
@@ -23464,7 +23615,7 @@ function getDomain(url, options = {}) {
|
|
|
23464
23615
|
result += OPEN_PARENTHESIS;
|
|
23465
23616
|
result += node.body.mediaQueryList.value;
|
|
23466
23617
|
result += CLOSE_PARENTHESIS;
|
|
23467
|
-
result += SPACE;
|
|
23618
|
+
result += SPACE$1;
|
|
23468
23619
|
}
|
|
23469
23620
|
result += node.body.selectorList.value;
|
|
23470
23621
|
if (node.body.remove) {
|
|
@@ -23668,7 +23819,7 @@ function getDomain(url, options = {}) {
|
|
|
23668
23819
|
});
|
|
23669
23820
|
// If there are at least one modifier, add a space
|
|
23670
23821
|
if (node.modifiers.children.some((modifier)=>modifier?.name.value)) {
|
|
23671
|
-
result += SPACE;
|
|
23822
|
+
result += SPACE$1;
|
|
23672
23823
|
}
|
|
23673
23824
|
}
|
|
23674
23825
|
// Body
|
|
@@ -23692,13 +23843,13 @@ function getDomain(url, options = {}) {
|
|
|
23692
23843
|
result.push(node.ip.value);
|
|
23693
23844
|
}
|
|
23694
23845
|
if (node.hostnames) {
|
|
23695
|
-
result.push(SPACE);
|
|
23696
|
-
result.push(node.hostnames.children.map(({ value })=>value).join(SPACE));
|
|
23846
|
+
result.push(SPACE$1);
|
|
23847
|
+
result.push(node.hostnames.children.map(({ value })=>value).join(SPACE$1));
|
|
23697
23848
|
}
|
|
23698
23849
|
if (node.comment) {
|
|
23699
|
-
result.push(SPACE);
|
|
23850
|
+
result.push(SPACE$1);
|
|
23700
23851
|
result.push(HASHMARK);
|
|
23701
|
-
result.push(SPACE);
|
|
23852
|
+
result.push(SPACE$1);
|
|
23702
23853
|
result.push(node.comment.value);
|
|
23703
23854
|
}
|
|
23704
23855
|
return result.join(EMPTY);
|
|
@@ -23868,7 +24019,7 @@ function getDomain(url, options = {}) {
|
|
|
23868
24019
|
}
|
|
23869
24020
|
|
|
23870
24021
|
/*
|
|
23871
|
-
* AGTree v4.2.1 (build date:
|
|
24022
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
23872
24023
|
* (c) 2026 Adguard Software Ltd.
|
|
23873
24024
|
* Released under the MIT license
|
|
23874
24025
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -23889,7 +24040,7 @@ function getDomain(url, options = {}) {
|
|
|
23889
24040
|
}
|
|
23890
24041
|
|
|
23891
24042
|
/*
|
|
23892
|
-
* AGTree v4.2.1 (build date:
|
|
24043
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
23893
24044
|
* (c) 2026 Adguard Software Ltd.
|
|
23894
24045
|
* Released under the MIT license
|
|
23895
24046
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -23937,7 +24088,7 @@ function getDomain(url, options = {}) {
|
|
|
23937
24088
|
};
|
|
23938
24089
|
|
|
23939
24090
|
/*
|
|
23940
|
-
* AGTree v4.2.1 (build date:
|
|
24091
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
23941
24092
|
* (c) 2026 Adguard Software Ltd.
|
|
23942
24093
|
* Released under the MIT license
|
|
23943
24094
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -24320,7 +24471,7 @@ const GenericPlatform = {
|
|
|
24320
24471
|
}
|
|
24321
24472
|
|
|
24322
24473
|
/*
|
|
24323
|
-
* AGTree v4.2.1 (build date:
|
|
24474
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
24324
24475
|
* (c) 2026 Adguard Software Ltd.
|
|
24325
24476
|
* Released under the MIT license
|
|
24326
24477
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -42514,7 +42665,7 @@ var cloneDeep = /*@__PURE__*/getDefaultExportFromCjs(cloneDeepExports);
|
|
|
42514
42665
|
}
|
|
42515
42666
|
|
|
42516
42667
|
/*
|
|
42517
|
-
* AGTree v4.2.1 (build date:
|
|
42668
|
+
* AGTree v4.2.1 (build date: Mon, 28 Sep 2026 19:57:19 GMT)
|
|
42518
42669
|
* (c) 2026 Adguard Software Ltd.
|
|
42519
42670
|
* Released under the MIT license
|
|
42520
42671
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -42628,7 +42779,7 @@ function createConversionResult(result, isConverted) {
|
|
|
42628
42779
|
const ruleClone = clone(rule);
|
|
42629
42780
|
ruleClone.marker.value = CommentMarker.Regular;
|
|
42630
42781
|
// Add the hashmark to the beginning of the comment text
|
|
42631
|
-
ruleClone.text.value = `${SPACE}${CommentMarker.Hashmark}${ruleClone.text.value}`;
|
|
42782
|
+
ruleClone.text.value = `${SPACE$1}${CommentMarker.Hashmark}${ruleClone.text.value}`;
|
|
42632
42783
|
return createNodeConversionResult([
|
|
42633
42784
|
ruleClone
|
|
42634
42785
|
], true);
|
|
@@ -44757,7 +44908,7 @@ const REMOVE_ATTR_CLASS_APPLYING = new Set([
|
|
|
44757
44908
|
switch(rule.syntax){
|
|
44758
44909
|
case AdblockSyntax.Abp:
|
|
44759
44910
|
prefix = ABP_SCRIPTLET_PREFIX;
|
|
44760
|
-
charToUnescape = SPACE;
|
|
44911
|
+
charToUnescape = SPACE$1;
|
|
44761
44912
|
break;
|
|
44762
44913
|
case AdblockSyntax.Ubo:
|
|
44763
44914
|
prefix = UBO_SCRIPTLET_PREFIX;
|
|
@@ -44972,7 +45123,7 @@ const REMOVE_ATTR_CLASS_APPLYING = new Set([
|
|
|
44972
45123
|
if (rule.syntax === AdblockSyntax.Abp) {
|
|
44973
45124
|
transformAllScriptletArguments(scriptletClone, (value)=>{
|
|
44974
45125
|
if (!isNull(value)) {
|
|
44975
|
-
return QuoteUtils.unescapeSingleEscapedOccurrences(value, SPACE);
|
|
45126
|
+
return QuoteUtils.unescapeSingleEscapedOccurrences(value, SPACE$1);
|
|
44976
45127
|
}
|
|
44977
45128
|
return value;
|
|
44978
45129
|
});
|
|
@@ -45354,7 +45505,7 @@ const REMOVE_ATTR_CLASS_APPLYING = new Set([
|
|
|
45354
45505
|
*/ /**
|
|
45355
45506
|
* @see {@link https://adguard.com/kb/general/ad-filtering/create-own-filters/#csp-modifier}
|
|
45356
45507
|
*/ const CSP_MODIFIER = 'csp';
|
|
45357
|
-
const CSP_SEPARATOR = SEMICOLON + SPACE;
|
|
45508
|
+
const CSP_SEPARATOR = SEMICOLON + SPACE$1;
|
|
45358
45509
|
/**
|
|
45359
45510
|
* @see {@link https://adguard.com/kb/general/ad-filtering/create-own-filters/#csp-modifier}
|
|
45360
45511
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy}
|
|
@@ -53824,35 +53975,300 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
53824
53975
|
}
|
|
53825
53976
|
|
|
53826
53977
|
/**
|
|
53827
|
-
*
|
|
53828
|
-
|
|
53978
|
+
* Describes an error when the metadata rules of a serialized ruleset are
|
|
53979
|
+
* missing, malformed or do not form valid JSON.
|
|
53980
|
+
*/ class InvalidMetadataChunksError extends Error {
|
|
53981
|
+
/**
|
|
53982
|
+
* Describes an error when the metadata rules of a serialized ruleset
|
|
53983
|
+
* cannot be read. The message names the rule set and the reason.
|
|
53984
|
+
*
|
|
53985
|
+
* @param rulesetId Rule set id whose metadata could not be read.
|
|
53986
|
+
* @param reason Why the metadata cannot be read.
|
|
53987
|
+
* @param cause Basic error, describes why the metadata is unreadable.
|
|
53988
|
+
*/ constructor(rulesetId, reason, cause){
|
|
53989
|
+
super(`Cannot read metadata of rule set '${rulesetId}': ${reason}`, {
|
|
53990
|
+
cause
|
|
53991
|
+
});
|
|
53992
|
+
this.name = this.constructor.name;
|
|
53993
|
+
this.rulesetId = rulesetId;
|
|
53994
|
+
// For proper work of the "instanceof" operator
|
|
53995
|
+
Object.setPrototypeOf(this, InvalidMetadataChunksError.prototype);
|
|
53996
|
+
}
|
|
53997
|
+
}
|
|
53998
|
+
|
|
53999
|
+
/**
|
|
54000
|
+
* Maximum size in UTF-8 bytes of one serialized `metadata` value of a
|
|
54001
|
+
* metadata rule, including JSON escaping and the `{"chunk":...}` wrapper.
|
|
54002
|
+
*/ const MAX_METADATA_VALUE_BYTES = 65536;
|
|
54003
|
+
/**
|
|
54004
|
+
* Key of the fragment inside the `metadata` value of a metadata rule.
|
|
54005
|
+
*/ const CHUNK_KEY = 'chunk';
|
|
54006
|
+
/**
|
|
54007
|
+
* Nesting depth of the `metadata` value inside a serialized ruleset file:
|
|
54008
|
+
* the rules array (0) contains rule objects (1) that contain the value (2).
|
|
54009
|
+
* Pretty printing indents every nested line by this many tabs.
|
|
54010
|
+
*/ const METADATA_VALUE_DEPTH = 2;
|
|
54011
|
+
/**
|
|
54012
|
+
* Code unit of the double quote character.
|
|
54013
|
+
*/ const QUOTE = 0x22;
|
|
54014
|
+
/**
|
|
54015
|
+
* Code unit of the backslash character.
|
|
54016
|
+
*/ const BACKSLASH = 0x5c;
|
|
54017
|
+
/**
|
|
54018
|
+
* First code unit that JSON.stringify does not escape.
|
|
54019
|
+
*/ const SPACE = 0x20;
|
|
53829
54020
|
/**
|
|
53830
|
-
*
|
|
53831
|
-
*/ const
|
|
54021
|
+
* First code unit of the surrogate range.
|
|
54022
|
+
*/ const SURROGATE_START = 0xd800;
|
|
54023
|
+
/**
|
|
54024
|
+
* Last code unit of the surrogate range.
|
|
54025
|
+
*/ const SURROGATE_END = 0xdfff;
|
|
54026
|
+
/**
|
|
54027
|
+
* First code point that UTF-8 encodes in two bytes.
|
|
54028
|
+
*/ const TWO_BYTE_UTF8_START = 0x80;
|
|
54029
|
+
/**
|
|
54030
|
+
* First code point that UTF-8 encodes in three bytes.
|
|
54031
|
+
*/ const THREE_BYTE_UTF8_START = 0x800;
|
|
54032
|
+
/**
|
|
54033
|
+
* Number of UTF-8 bytes of a surrogate pair.
|
|
54034
|
+
*/ const SURROGATE_PAIR_BYTES = 4;
|
|
54035
|
+
/**
|
|
54036
|
+
* Control characters that JSON.stringify writes as two-character escapes
|
|
54037
|
+
* (`\b`, `\t`, `\n`, `\f`, `\r`). Other control characters become `\u00XX`.
|
|
54038
|
+
*/ const SHORT_ESCAPES = new Set([
|
|
54039
|
+
0x08,
|
|
54040
|
+
0x09,
|
|
54041
|
+
0x0a,
|
|
54042
|
+
0x0c,
|
|
54043
|
+
0x0d
|
|
54044
|
+
]);
|
|
54045
|
+
/**
|
|
54046
|
+
* Shared encoder for byte measurements.
|
|
54047
|
+
*/ const utf8Encoder = new TextEncoder();
|
|
54048
|
+
/**
|
|
54049
|
+
* Byte accounting, splitting of serialized metadata into fragments and id
|
|
54050
|
+
* allocation for metadata rules.
|
|
54051
|
+
*/ class MetadataChunks {
|
|
54052
|
+
/**
|
|
54053
|
+
* Returns the size of a string in UTF-8 bytes.
|
|
54054
|
+
*
|
|
54055
|
+
* @param str String to measure.
|
|
54056
|
+
*
|
|
54057
|
+
* @returns Number of UTF-8 bytes.
|
|
54058
|
+
*/ static utf8ByteLength(str) {
|
|
54059
|
+
return utf8Encoder.encode(str).length;
|
|
54060
|
+
}
|
|
54061
|
+
/**
|
|
54062
|
+
* Returns the number of UTF-8 bytes that one UTF-16 code unit occupies once
|
|
54063
|
+
* `JSON.stringify` has escaped it inside a string literal. A code unit of a
|
|
54064
|
+
* surrogate pair must not be passed here: pairs cost four bytes and are
|
|
54065
|
+
* handled by the caller.
|
|
54066
|
+
*
|
|
54067
|
+
* @param codeUnit UTF-16 code unit.
|
|
54068
|
+
*
|
|
54069
|
+
* @returns Escaped size in bytes.
|
|
54070
|
+
*/ static escapedByteCost(codeUnit) {
|
|
54071
|
+
if (codeUnit === QUOTE || codeUnit === BACKSLASH) {
|
|
54072
|
+
return 2;
|
|
54073
|
+
}
|
|
54074
|
+
if (codeUnit < SPACE) {
|
|
54075
|
+
return SHORT_ESCAPES.has(codeUnit) ? 2 : 6;
|
|
54076
|
+
}
|
|
54077
|
+
// A lone surrogate is written as `\uXXXX`.
|
|
54078
|
+
if (codeUnit >= SURROGATE_START && codeUnit <= SURROGATE_END) {
|
|
54079
|
+
return 6;
|
|
54080
|
+
}
|
|
54081
|
+
if (codeUnit < TWO_BYTE_UTF8_START) {
|
|
54082
|
+
return 1;
|
|
54083
|
+
}
|
|
54084
|
+
if (codeUnit < THREE_BYTE_UTF8_START) {
|
|
54085
|
+
return 2;
|
|
54086
|
+
}
|
|
54087
|
+
return 3;
|
|
54088
|
+
}
|
|
54089
|
+
/**
|
|
54090
|
+
* Renders the `metadata` value of a metadata rule exactly as it appears in a
|
|
54091
|
+
* serialized ruleset file, so that its byte size can be measured.
|
|
54092
|
+
*
|
|
54093
|
+
* @param chunk Fragment stored in the value.
|
|
54094
|
+
* @param pretty Whether the file is pretty printed with {@link TAB} indents.
|
|
54095
|
+
*
|
|
54096
|
+
* @returns The value as written to the file.
|
|
54097
|
+
*/ static renderValue(chunk, pretty) {
|
|
54098
|
+
const chunkJson = JSON.stringify(chunk);
|
|
54099
|
+
if (!pretty) {
|
|
54100
|
+
return `{"${CHUNK_KEY}":${chunkJson}}`;
|
|
54101
|
+
}
|
|
54102
|
+
const inner = TAB.repeat(METADATA_VALUE_DEPTH + 1);
|
|
54103
|
+
const outer = TAB.repeat(METADATA_VALUE_DEPTH);
|
|
54104
|
+
return `{\n${inner}"${CHUNK_KEY}": ${chunkJson}\n${outer}}`;
|
|
54105
|
+
}
|
|
54106
|
+
/**
|
|
54107
|
+
* Splits a serialized payload into ordered fragments such that the
|
|
54108
|
+
* `metadata` value rendered from each fragment (see
|
|
54109
|
+
* {@link MetadataChunks.renderValue}) is at most {@link MAX_METADATA_VALUE_BYTES}.
|
|
54110
|
+
* Fragments are cut on code-point boundaries, so a surrogate pair is never
|
|
54111
|
+
* split. The result is a pure function of the input: identical payloads
|
|
54112
|
+
* produce identical fragments.
|
|
54113
|
+
*
|
|
54114
|
+
* @param payload Serialized metadata (JSON text).
|
|
54115
|
+
* @param pretty Whether the ruleset file is pretty printed.
|
|
54116
|
+
*
|
|
54117
|
+
* @returns Ordered fragments whose concatenation is `payload`.
|
|
54118
|
+
*
|
|
54119
|
+
* @throws Error if a rendered fragment exceeds the bound. This cannot happen
|
|
54120
|
+
* unless {@link MetadataChunks.escapedByteCost} disagrees with `JSON.stringify`.
|
|
54121
|
+
*/ static split(payload, pretty) {
|
|
54122
|
+
const budget = MAX_METADATA_VALUE_BYTES - MetadataChunks.utf8ByteLength(MetadataChunks.renderValue('', pretty));
|
|
54123
|
+
const fragments = [];
|
|
54124
|
+
let start = 0;
|
|
54125
|
+
let bytes = 0;
|
|
54126
|
+
let i = 0;
|
|
54127
|
+
// Iterating a string yields code points: a surrogate pair comes as one
|
|
54128
|
+
// two-unit string, a lone surrogate as one unit that `escapedByteCost`
|
|
54129
|
+
// prices as a `\uXXXX` escape.
|
|
54130
|
+
for (const char of payload){
|
|
54131
|
+
const cost = char.length === 2 ? SURROGATE_PAIR_BYTES : MetadataChunks.escapedByteCost(char.charCodeAt(0));
|
|
54132
|
+
if (bytes + cost > budget) {
|
|
54133
|
+
fragments.push(payload.slice(start, i));
|
|
54134
|
+
start = i;
|
|
54135
|
+
bytes = 0;
|
|
54136
|
+
}
|
|
54137
|
+
bytes += cost;
|
|
54138
|
+
i += char.length;
|
|
54139
|
+
}
|
|
54140
|
+
fragments.push(payload.slice(start));
|
|
54141
|
+
// Measure the real output as a guard against the cost table drifting
|
|
54142
|
+
// from the engine's escaping rules.
|
|
54143
|
+
for (const fragment of fragments){
|
|
54144
|
+
const size = MetadataChunks.utf8ByteLength(MetadataChunks.renderValue(fragment, pretty));
|
|
54145
|
+
if (size > MAX_METADATA_VALUE_BYTES) {
|
|
54146
|
+
throw new Error(`Metadata chunk of ${size} bytes exceeds ${MAX_METADATA_VALUE_BYTES} bytes ` + '(internal error: byte accounting disagrees with JSON.stringify)');
|
|
54147
|
+
}
|
|
54148
|
+
}
|
|
54149
|
+
return fragments;
|
|
54150
|
+
}
|
|
54151
|
+
/**
|
|
54152
|
+
* Allocates ids for metadata rules: the smallest positive integers that no
|
|
54153
|
+
* other rule of the ruleset uses, in increasing order. Ordinary rule ids are
|
|
54154
|
+
* stable hashes of the rule text and are never changed to make room.
|
|
54155
|
+
*
|
|
54156
|
+
* @param count Number of ids to allocate.
|
|
54157
|
+
* @param usedIds Ids taken by ordinary rules and by unsafe rules stored in
|
|
54158
|
+
* the metadata.
|
|
54159
|
+
*
|
|
54160
|
+
* @returns Allocated ids, one per metadata rule.
|
|
54161
|
+
*/ static allocateIds(count, usedIds) {
|
|
54162
|
+
const ids = [];
|
|
54163
|
+
let candidate = 1;
|
|
54164
|
+
while(ids.length < count){
|
|
54165
|
+
if (!usedIds.has(candidate)) {
|
|
54166
|
+
ids.push(candidate);
|
|
54167
|
+
}
|
|
54168
|
+
candidate += 1;
|
|
54169
|
+
}
|
|
54170
|
+
return ids;
|
|
54171
|
+
}
|
|
54172
|
+
}
|
|
54173
|
+
|
|
53832
54174
|
/**
|
|
53833
|
-
* Dummy rule URL that should not match any request.
|
|
54175
|
+
* Dummy rule URL that should not match any request. It is also the marker
|
|
54176
|
+
* that identifies metadata rules when a ruleset is read.
|
|
53834
54177
|
*/ const DUMMY_RULE_URL = 'dummy.rule.adguard.com';
|
|
53835
54178
|
/**
|
|
53836
|
-
*
|
|
53837
|
-
|
|
53838
|
-
|
|
53839
|
-
|
|
53840
|
-
|
|
53841
|
-
|
|
53842
|
-
|
|
53843
|
-
|
|
53844
|
-
|
|
53845
|
-
|
|
53846
|
-
|
|
53847
|
-
|
|
53848
|
-
|
|
53849
|
-
|
|
53850
|
-
|
|
53851
|
-
|
|
53852
|
-
|
|
53853
|
-
|
|
53854
|
-
|
|
53855
|
-
|
|
54179
|
+
* Writes and reads metadata rules.
|
|
54180
|
+
*/ class MetadataRules {
|
|
54181
|
+
/**
|
|
54182
|
+
* Checks whether a parsed rule is a metadata rule: an object whose
|
|
54183
|
+
* `condition.urlFilter` is the dummy URL marker and that has an own
|
|
54184
|
+
* `metadata` property. Ordinary converted rules never carry `metadata`, so a
|
|
54185
|
+
* converted rule for the marker host without that property is an ordinary
|
|
54186
|
+
* rule.
|
|
54187
|
+
*
|
|
54188
|
+
* @param rule Parsed rule.
|
|
54189
|
+
*
|
|
54190
|
+
* @returns `true` if the rule is a metadata rule.
|
|
54191
|
+
*/ static isMetadataRule(rule) {
|
|
54192
|
+
return typeof rule === 'object' && rule !== null && rule.condition?.urlFilter === DUMMY_RULE_URL && Object.hasOwn(rule, 'metadata');
|
|
54193
|
+
}
|
|
54194
|
+
/**
|
|
54195
|
+
* Serializes a metadata payload and wraps its fragments into metadata rules.
|
|
54196
|
+
* Every rule's `metadata` value fits the per-value size bound in the given
|
|
54197
|
+
* formatting mode.
|
|
54198
|
+
*
|
|
54199
|
+
* @param payload Metadata object; must be JSON serializable.
|
|
54200
|
+
* @param usedIds Ids taken by ordinary rules and by unsafe rules stored in
|
|
54201
|
+
* the metadata; metadata rules get the smallest ids outside this set.
|
|
54202
|
+
* @param pretty Whether the ruleset file will be pretty printed.
|
|
54203
|
+
*
|
|
54204
|
+
* @returns Metadata rules in fragment order.
|
|
54205
|
+
*/ static create(payload, usedIds, pretty) {
|
|
54206
|
+
const fragments = MetadataChunks.split(serializeJson(payload), pretty);
|
|
54207
|
+
const ids = MetadataChunks.allocateIds(fragments.length, usedIds);
|
|
54208
|
+
return fragments.map((chunk, i)=>({
|
|
54209
|
+
id: ids[i],
|
|
54210
|
+
action: {
|
|
54211
|
+
type: RuleActionType.Block
|
|
54212
|
+
},
|
|
54213
|
+
condition: {
|
|
54214
|
+
urlFilter: DUMMY_RULE_URL,
|
|
54215
|
+
resourceTypes: [
|
|
54216
|
+
ResourceType$1.XmlHttpRequest
|
|
54217
|
+
]
|
|
54218
|
+
},
|
|
54219
|
+
metadata: {
|
|
54220
|
+
[CHUNK_KEY]: chunk
|
|
54221
|
+
}
|
|
54222
|
+
}));
|
|
54223
|
+
}
|
|
54224
|
+
/**
|
|
54225
|
+
* Reads the metadata rules of a parsed ruleset: takes the leading run of
|
|
54226
|
+
* metadata rules (see {@link MetadataRules.isMetadataRule}), joins their fragments in order
|
|
54227
|
+
* and parses the result once. Metadata rule ids are ignored. A rule with the
|
|
54228
|
+
* marker `urlFilter` but without a `metadata` property is an ordinary rule.
|
|
54229
|
+
*
|
|
54230
|
+
* @param rulesetId Rule set id, used in error messages.
|
|
54231
|
+
* @param rules Parsed content of a ruleset file.
|
|
54232
|
+
*
|
|
54233
|
+
* @returns Parsed payload, the remaining rules and the number of metadata
|
|
54234
|
+
* rules.
|
|
54235
|
+
*
|
|
54236
|
+
* @throws {InvalidMetadataChunksError} If `rules` is not an array, has no
|
|
54237
|
+
* leading metadata rule, has a metadata rule without a string `chunk`, or if
|
|
54238
|
+
* the joined fragments are not valid JSON.
|
|
54239
|
+
*/ static read(rulesetId, rules) {
|
|
54240
|
+
if (!Array.isArray(rules)) {
|
|
54241
|
+
throw new InvalidMetadataChunksError(rulesetId, 'expected an array of declarative rules');
|
|
54242
|
+
}
|
|
54243
|
+
const fragments = [];
|
|
54244
|
+
let index = 0;
|
|
54245
|
+
for (const rule of rules){
|
|
54246
|
+
if (!MetadataRules.isMetadataRule(rule)) {
|
|
54247
|
+
break;
|
|
54248
|
+
}
|
|
54249
|
+
const chunk = rule.metadata?.[CHUNK_KEY];
|
|
54250
|
+
if (typeof chunk !== 'string') {
|
|
54251
|
+
throw new InvalidMetadataChunksError(rulesetId, `"metadata.${CHUNK_KEY}" of metadata rule #${index} is not a string`);
|
|
54252
|
+
}
|
|
54253
|
+
fragments.push(chunk);
|
|
54254
|
+
index += 1;
|
|
54255
|
+
}
|
|
54256
|
+
if (fragments.length === 0) {
|
|
54257
|
+
throw new InvalidMetadataChunksError(rulesetId, 'no metadata rules found at the beginning of the rule set');
|
|
54258
|
+
}
|
|
54259
|
+
let payload;
|
|
54260
|
+
try {
|
|
54261
|
+
payload = JSON.parse(fragments.join(''));
|
|
54262
|
+
} catch (e) {
|
|
54263
|
+
throw new InvalidMetadataChunksError(rulesetId, `metadata chunks do not form valid JSON: ${getErrorMessage(e)}`, e);
|
|
54264
|
+
}
|
|
54265
|
+
return {
|
|
54266
|
+
payload,
|
|
54267
|
+
declarativeRules: rules.slice(index),
|
|
54268
|
+
metadataRulesCount: index
|
|
54269
|
+
};
|
|
54270
|
+
}
|
|
54271
|
+
}
|
|
53856
54272
|
|
|
53857
54273
|
/**
|
|
53858
54274
|
* Base64 alphabet used by the standard source-map VLQ encoding.
|
|
@@ -54164,6 +54580,9 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
54164
54580
|
/** @inheritdoc */ getRegexpRulesCount() {
|
|
54165
54581
|
return this.regexpRulesCount;
|
|
54166
54582
|
}
|
|
54583
|
+
/** @inheritdoc */ getMetadataRulesCount() {
|
|
54584
|
+
return this.metadataRulesCount;
|
|
54585
|
+
}
|
|
54167
54586
|
/** @inheritdoc */ getId() {
|
|
54168
54587
|
return this.id;
|
|
54169
54588
|
}
|
|
@@ -54329,15 +54748,106 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
54329
54748
|
* @throws Error {@link UnavailableRulesetSourceError} if rule set source
|
|
54330
54749
|
* is not available.
|
|
54331
54750
|
*/ static async deserialize(id, rawData, loadLazyData, loadDeclarativeRules, filterList) {
|
|
54332
|
-
|
|
54751
|
+
const data = RulesetWithSourceMap.parseData(id, ()=>JSON.parse(rawData));
|
|
54752
|
+
const rulesetContentProvider = RulesetWithSourceMap.createContentProvider(id, async ()=>JSON.parse(await loadLazyData()), async ()=>JSON.parse(await loadDeclarativeRules()), filterList);
|
|
54753
|
+
return {
|
|
54754
|
+
id,
|
|
54755
|
+
data,
|
|
54756
|
+
rulesetContentProvider
|
|
54757
|
+
};
|
|
54758
|
+
}
|
|
54759
|
+
/**
|
|
54760
|
+
* Creates a rule set from the content of a compact ruleset file read by
|
|
54761
|
+
* {@link parseCompactRuleset}, without serializing its parts back to
|
|
54762
|
+
* strings. The metadata is validated at once with the same schema as in
|
|
54763
|
+
* {@link RulesetWithSourceMap.deserialize}; the lazy metadata and the
|
|
54764
|
+
* declarative rules are validated when the content is first loaded.
|
|
54765
|
+
*
|
|
54766
|
+
* The rule set keeps references to `content.lazyMetadata` and
|
|
54767
|
+
* `content.declarativeRules` for its whole lifetime, so the parsed file
|
|
54768
|
+
* stays in memory. Calling {@link RulesetWithSourceMap.unloadContent}
|
|
54769
|
+
* releases only the validated copies made on load, not this content. When
|
|
54770
|
+
* the content must be released, for example in a long-running extension,
|
|
54771
|
+
* keep it in storage and use {@link RulesetWithSourceMap.deserialize} with
|
|
54772
|
+
* loaders instead.
|
|
54773
|
+
*
|
|
54774
|
+
* @param rulesetId Id of rule set.
|
|
54775
|
+
* @param content Parsed content of the ruleset file: `metadata`,
|
|
54776
|
+
* `lazyMetadata`, ordinary `declarativeRules` and `metadataRulesCount`, as
|
|
54777
|
+
* returned by {@link parseCompactRuleset}.
|
|
54778
|
+
* @param filterList List of {@link IFilter} the rule set was converted from.
|
|
54779
|
+
*
|
|
54780
|
+
* @returns Rule set ready to use.
|
|
54781
|
+
*
|
|
54782
|
+
* @throws Error {@link UnavailableRulesetSourceError} if the metadata does
|
|
54783
|
+
* not match {@link SerializedRulesetData}. Errors of
|
|
54784
|
+
* {@link RulesetWithSourceMap.fromDeserialized} come unwrapped.
|
|
54785
|
+
*/ static fromCompact(rulesetId, content, filterList) {
|
|
54786
|
+
const data = RulesetWithSourceMap.parseData(rulesetId, ()=>content.metadata);
|
|
54787
|
+
const rulesetContentProvider = RulesetWithSourceMap.createContentProvider(rulesetId, async ()=>content.lazyMetadata, async ()=>content.declarativeRules, filterList);
|
|
54788
|
+
return RulesetWithSourceMap.fromDeserialized({
|
|
54789
|
+
id: rulesetId,
|
|
54790
|
+
data,
|
|
54791
|
+
rulesetContentProvider
|
|
54792
|
+
}, content.metadataRulesCount);
|
|
54793
|
+
}
|
|
54794
|
+
/**
|
|
54795
|
+
* Creates a rule set from the result of
|
|
54796
|
+
* {@link RulesetWithSourceMap.deserialize}: builds the `$badfilter` rules
|
|
54797
|
+
* and the rules hash map from the serialized data and calls the
|
|
54798
|
+
* constructor.
|
|
54799
|
+
*
|
|
54800
|
+
* @param deserialized Deserialized rule set data and content provider.
|
|
54801
|
+
* @param metadataRulesCount Number of metadata rules in the ruleset file
|
|
54802
|
+
* the data was read from, `metadataRulesCount` of
|
|
54803
|
+
* {@link parseCompactRuleset}.
|
|
54804
|
+
*
|
|
54805
|
+
* @returns Rule set ready to use.
|
|
54806
|
+
*
|
|
54807
|
+
* @throws Error if a `$badfilter` rule text cannot be parsed
|
|
54808
|
+
* ({@link Rule.createFromText}), and `SyntaxError` if the serialized rules
|
|
54809
|
+
* hash map is not valid JSON ({@link RulesHashMap.deserializeSources}).
|
|
54810
|
+
* Both come unwrapped: the data is produced by this converter, so such an
|
|
54811
|
+
* error is a producer bug, not an unavailable source.
|
|
54812
|
+
*/ static fromDeserialized(deserialized, metadataRulesCount) {
|
|
54813
|
+
const { id, data, rulesetContentProvider } = deserialized;
|
|
54814
|
+
// Rules with `$badfilter` are used only for matching, not for source
|
|
54815
|
+
// attribution, so filter id and rule index are not needed.
|
|
54816
|
+
const badFilterRules = data.badFilterRulesRaw.flatMap((rawRule)=>Rule.createFromText(0, 0, rawRule));
|
|
54817
|
+
const rulesHashMap = new RulesHashMap(RulesHashMap.deserializeSources(data.rulesetHashMapRaw));
|
|
54818
|
+
return new RulesetWithSourceMap(id, data.safeRulesCount, data.unsafeRulesCount, data.regexpRulesCount, rulesetContentProvider, badFilterRules, rulesHashMap, data.unsafeRules, metadataRulesCount);
|
|
54819
|
+
}
|
|
54820
|
+
/**
|
|
54821
|
+
* Validates serialized rule set data.
|
|
54822
|
+
*
|
|
54823
|
+
* @param id Id of rule set.
|
|
54824
|
+
* @param getData Returns the data to validate; parsing errors thrown by it
|
|
54825
|
+
* are wrapped as well.
|
|
54826
|
+
*
|
|
54827
|
+
* @returns Validated rule set data.
|
|
54828
|
+
*
|
|
54829
|
+
* @throws Error {@link UnavailableRulesetSourceError} if the data cannot be
|
|
54830
|
+
* obtained or does not match {@link SerializedRulesetData}.
|
|
54831
|
+
*/ static parseData(id, getData) {
|
|
54333
54832
|
try {
|
|
54334
|
-
|
|
54335
|
-
data = v__namespace.parse(serializedRulesetDataValidator, objectFromString);
|
|
54833
|
+
return v__namespace.parse(serializedRulesetDataValidator, getData());
|
|
54336
54834
|
} catch (e) {
|
|
54337
54835
|
// eslint-disable-next-line max-len
|
|
54338
54836
|
const msg = `Cannot parse serialized ruleset's data with id "${id}", got error: ${getErrorMessage(e)}`;
|
|
54339
54837
|
throw new UnavailableRulesetSourceError(msg, id, e);
|
|
54340
54838
|
}
|
|
54839
|
+
}
|
|
54840
|
+
/**
|
|
54841
|
+
* Creates a content provider that loads and validates the lazy metadata
|
|
54842
|
+
* once and validates declarative rules on each load.
|
|
54843
|
+
*
|
|
54844
|
+
* @param id Id of rule set.
|
|
54845
|
+
* @param loadLazyData Loads the parsed {@link SerializedRulesetLazyData}.
|
|
54846
|
+
* @param loadDeclarativeRules Loads the parsed list of declarative rules.
|
|
54847
|
+
* @param filterList List of {@link IFilter}.
|
|
54848
|
+
*
|
|
54849
|
+
* @returns Rule set content provider.
|
|
54850
|
+
*/ static createContentProvider(id, loadLazyData, loadDeclarativeRules, filterList) {
|
|
54341
54851
|
/**
|
|
54342
54852
|
* This variable is used as a singleton for all three functions
|
|
54343
54853
|
* (`loadSourceMap`, `loadFilterList`, `loadDeclarativeRules`) to load
|
|
@@ -54348,9 +54858,7 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
54348
54858
|
return deserializedLazyData;
|
|
54349
54859
|
}
|
|
54350
54860
|
try {
|
|
54351
|
-
const
|
|
54352
|
-
const objectFromString = JSON.parse(lazyData);
|
|
54353
|
-
const parsed = v__namespace.parse(serializedRulesetLazyDataValidator, objectFromString);
|
|
54861
|
+
const parsed = v__namespace.parse(serializedRulesetLazyDataValidator, await loadLazyData());
|
|
54354
54862
|
deserializedLazyData = parsed;
|
|
54355
54863
|
return parsed;
|
|
54356
54864
|
} catch (e) {
|
|
@@ -54359,28 +54867,20 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
54359
54867
|
throw new UnavailableRulesetSourceError(msg, id, e);
|
|
54360
54868
|
}
|
|
54361
54869
|
};
|
|
54362
|
-
|
|
54363
|
-
|
|
54364
|
-
|
|
54365
|
-
|
|
54366
|
-
|
|
54367
|
-
|
|
54368
|
-
|
|
54369
|
-
|
|
54370
|
-
|
|
54371
|
-
|
|
54372
|
-
|
|
54373
|
-
|
|
54374
|
-
},
|
|
54375
|
-
loadDeclarativeRules: async ()=>{
|
|
54376
|
-
const rawFileContent = await loadDeclarativeRules();
|
|
54377
|
-
const objectFromString = JSON.parse(rawFileContent);
|
|
54378
|
-
const declarativeRules = v__namespace.parse(v__namespace.array(DeclarativeRuleValidator), objectFromString);
|
|
54379
|
-
return declarativeRules;
|
|
54380
|
-
}
|
|
54870
|
+
return {
|
|
54871
|
+
loadSourceMap: async ()=>{
|
|
54872
|
+
const { sourceMapRaw } = await getLazyData();
|
|
54873
|
+
const sources = SourceMap.deserializeSources(sourceMapRaw);
|
|
54874
|
+
return new SourceMap(sources);
|
|
54875
|
+
},
|
|
54876
|
+
loadFilterList: async ()=>{
|
|
54877
|
+
const { filterIds } = await getLazyData();
|
|
54878
|
+
return filterList.filter((filter)=>filterIds.includes(filter.getId()));
|
|
54879
|
+
},
|
|
54880
|
+
loadDeclarativeRules: async ()=>{
|
|
54881
|
+
return v__namespace.parse(v__namespace.array(DeclarativeRuleValidator), await loadDeclarativeRules());
|
|
54381
54882
|
}
|
|
54382
54883
|
};
|
|
54383
|
-
return deserialized;
|
|
54384
54884
|
}
|
|
54385
54885
|
/**
|
|
54386
54886
|
* Helper method to get serialized rule set data.
|
|
@@ -54451,27 +54951,28 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
54451
54951
|
const msg = `Unsafe rules count is not equal to the length of provided unsafe rules array in rule set '${id}'`;
|
|
54452
54952
|
throw new Error(msg);
|
|
54453
54953
|
}
|
|
54454
|
-
const
|
|
54954
|
+
const envelope = {
|
|
54455
54955
|
metadata: this.getSerializedRulesetData(unsafeRules),
|
|
54456
54956
|
lazyMetadata: this.getSerializedRulesetLazyData(),
|
|
54457
54957
|
filterContent: content
|
|
54458
|
-
}
|
|
54459
|
-
|
|
54460
|
-
//
|
|
54461
|
-
//
|
|
54462
|
-
|
|
54463
|
-
declarativeRules =
|
|
54464
|
-
|
|
54465
|
-
|
|
54466
|
-
//
|
|
54467
|
-
|
|
54468
|
-
|
|
54469
|
-
declarativeRules
|
|
54470
|
-
|
|
54471
|
-
|
|
54472
|
-
|
|
54473
|
-
|
|
54474
|
-
|
|
54958
|
+
};
|
|
54959
|
+
const unsafeIds = new Set(unsafeRules.map((rule)=>rule.id));
|
|
54960
|
+
// Exclude unsafe rules from declarative rules. `filter()` returns a
|
|
54961
|
+
// new array, so the internal state of the ruleset is never mutated
|
|
54962
|
+
// and repeated calls stay independent.
|
|
54963
|
+
const declarativeRules = (await this.getDeclarativeRules()).filter((rule)=>!unsafeIds.has(rule.id));
|
|
54964
|
+
// Metadata rules take the smallest ids not used by any rule of the
|
|
54965
|
+
// file, including the unsafe rules stored inside the metadata, so
|
|
54966
|
+
// no id appears twice anywhere in the ruleset.
|
|
54967
|
+
const usedIds = new Set([
|
|
54968
|
+
...unsafeIds,
|
|
54969
|
+
...declarativeRules.map((rule)=>rule.id)
|
|
54970
|
+
]);
|
|
54971
|
+
const metadataRules = MetadataRules.create(envelope, usedIds, prettyPrint);
|
|
54972
|
+
return serializeJson([
|
|
54973
|
+
...metadataRules,
|
|
54974
|
+
...declarativeRules
|
|
54975
|
+
], prettyPrint);
|
|
54475
54976
|
}
|
|
54476
54977
|
/**
|
|
54477
54978
|
* Constructor of RulesetWithSourceMap.
|
|
@@ -54485,7 +54986,9 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
54485
54986
|
* @param badFilterRules List of rules with $badfilter modifier.
|
|
54486
54987
|
* @param rulesHashMap Dictionary with hashes for all source rules.
|
|
54487
54988
|
* @param unsafeRules List of unsafe DNR rules.
|
|
54488
|
-
|
|
54989
|
+
* @param metadataRulesCount Number of metadata rules in the ruleset file
|
|
54990
|
+
* the rule set was read from, 0 if it was not read from a file.
|
|
54991
|
+
*/ constructor(id, safeRulesCount, unsafeRulesCount, regexpRulesCount, rulesetContentProvider, badFilterRules, rulesHashMap, unsafeRules, metadataRulesCount = 0){
|
|
54489
54992
|
/**
|
|
54490
54993
|
* Array of converted declarative rules.
|
|
54491
54994
|
*/ this.declarativeRules = [];
|
|
@@ -54513,6 +55016,7 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
54513
55016
|
this.badFilterRules = badFilterRules;
|
|
54514
55017
|
this.rulesHashMap = rulesHashMap;
|
|
54515
55018
|
this.unsafeRules = unsafeRules;
|
|
55019
|
+
this.metadataRulesCount = metadataRulesCount;
|
|
54516
55020
|
this.contentLoader = new LazyLoader(async ()=>{
|
|
54517
55021
|
const { loadSourceMap, loadFilterList, loadDeclarativeRules } = this.rulesetContentProvider;
|
|
54518
55022
|
this.sourceMap = await loadSourceMap();
|
|
@@ -55060,6 +55564,35 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55060
55564
|
* filter content into individual rules.
|
|
55061
55565
|
*/ Filter.LINE_SPLITTER = /\r?\n/;
|
|
55062
55566
|
|
|
55567
|
+
/**
|
|
55568
|
+
* Reads a parsed filter ruleset file: joins the leading metadata rules,
|
|
55569
|
+
* parses the metadata once and returns it with the ordinary rules and the
|
|
55570
|
+
* number of metadata rules. The payload is taken as the envelope written by
|
|
55571
|
+
* {@link RulesetWithSourceMap.serializeCompact} without further checks, and
|
|
55572
|
+
* ordinary rules are returned as parsed; both are validated later by
|
|
55573
|
+
* {@link RulesetWithSourceMap.fromCompact} or
|
|
55574
|
+
* {@link RulesetWithSourceMap.deserialize} and the ruleset content provider.
|
|
55575
|
+
*
|
|
55576
|
+
* @param rulesetId Rule set id, used in error messages.
|
|
55577
|
+
* @param parsedRuleset Parsed JSON content of a `ruleset_N.json` file.
|
|
55578
|
+
*
|
|
55579
|
+
* @returns Envelope fields, ordinary rules and metadata rule count.
|
|
55580
|
+
*
|
|
55581
|
+
* @throws {InvalidMetadataChunksError} If `parsedRuleset` is not an array,
|
|
55582
|
+
* has no leading metadata rule, has a metadata rule without a string `chunk`,
|
|
55583
|
+
* or if the joined fragments are not valid JSON.
|
|
55584
|
+
*/ function parseCompactRuleset(rulesetId, parsedRuleset) {
|
|
55585
|
+
const { payload, declarativeRules, metadataRulesCount } = MetadataRules.read(rulesetId, parsedRuleset);
|
|
55586
|
+
const { metadata, lazyMetadata, filterContent } = payload;
|
|
55587
|
+
return {
|
|
55588
|
+
metadata,
|
|
55589
|
+
lazyMetadata,
|
|
55590
|
+
filterContent,
|
|
55591
|
+
declarativeRules,
|
|
55592
|
+
metadataRulesCount
|
|
55593
|
+
};
|
|
55594
|
+
}
|
|
55595
|
+
|
|
55063
55596
|
/**
|
|
55064
55597
|
* Metadata ruleset ID.
|
|
55065
55598
|
*/ const METADATA_RULESET_ID = 0;
|
|
@@ -55067,7 +55600,8 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55067
55600
|
* Checksum map validator.
|
|
55068
55601
|
*/ const checksumMapValidator = v__namespace.record(v__namespace.string(), v__namespace.string());
|
|
55069
55602
|
/**
|
|
55070
|
-
* Metadata validator.
|
|
55603
|
+
* Metadata validator. Uses `v.strictObject` so unknown payload keys are
|
|
55604
|
+
* rejected at deserialization time.
|
|
55071
55605
|
*/ const metadataValidator = v__namespace.strictObject({
|
|
55072
55606
|
/**
|
|
55073
55607
|
* Checksums for all rulesets.
|
|
@@ -55079,16 +55613,6 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55079
55613
|
* Validation should be performed by users.
|
|
55080
55614
|
*/ additionalProperties: v__namespace.record(v__namespace.string(), v__namespace.unknown())
|
|
55081
55615
|
});
|
|
55082
|
-
/**
|
|
55083
|
-
* Metadata rule validator.
|
|
55084
|
-
*
|
|
55085
|
-
* Uses `v.looseObject` to allow additional Chrome DNR fields (`id`,
|
|
55086
|
-
* `priority`, `action`, `condition` etc.) that are outside our control.
|
|
55087
|
-
* The nested `metadata` field uses `v.strictObject()` so unknown metadata
|
|
55088
|
-
* keys are rejected at deserialization time.
|
|
55089
|
-
*/ const metadataRuleValidator = v__namespace.looseObject({
|
|
55090
|
-
metadata: metadataValidator
|
|
55091
|
-
});
|
|
55092
55616
|
/**
|
|
55093
55617
|
* Represents a specialized metadata ruleset for managing and validating
|
|
55094
55618
|
* metadata associated with various rulesets.
|
|
@@ -55111,7 +55635,7 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55111
55635
|
* @param rulesetId Rule set id.
|
|
55112
55636
|
* @param checksum Checksum.
|
|
55113
55637
|
*/ setChecksum(rulesetId, checksum) {
|
|
55114
|
-
this.
|
|
55638
|
+
this.metadata.checksums[rulesetId] = checksum;
|
|
55115
55639
|
}
|
|
55116
55640
|
/**
|
|
55117
55641
|
* Returns checksum for the specified rule set.
|
|
@@ -55120,14 +55644,14 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55120
55644
|
*
|
|
55121
55645
|
* @returns Checksum or undefined if not found.
|
|
55122
55646
|
*/ getChecksum(rulesetId) {
|
|
55123
|
-
return this.
|
|
55647
|
+
return this.metadata.checksums[rulesetId];
|
|
55124
55648
|
}
|
|
55125
55649
|
/**
|
|
55126
55650
|
* Returns all rule set ids in the metadata.
|
|
55127
55651
|
*
|
|
55128
55652
|
* @returns Rule set ids.
|
|
55129
55653
|
*/ getRulesetIds() {
|
|
55130
|
-
return Object.keys(this.
|
|
55654
|
+
return Object.keys(this.metadata.checksums);
|
|
55131
55655
|
}
|
|
55132
55656
|
/**
|
|
55133
55657
|
* Gets additional property.
|
|
@@ -55136,7 +55660,7 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55136
55660
|
*
|
|
55137
55661
|
* @returns Property value or undefined if not found.
|
|
55138
55662
|
*/ getAdditionalProperty(key) {
|
|
55139
|
-
return this.
|
|
55663
|
+
return this.metadata.additionalProperties[key];
|
|
55140
55664
|
}
|
|
55141
55665
|
/**
|
|
55142
55666
|
* Sets additional property.
|
|
@@ -55145,7 +55669,7 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55145
55669
|
* @param value Property value. The class does not validate that the value is
|
|
55146
55670
|
* JSON-serializable; callers are responsible for ensuring serializability.
|
|
55147
55671
|
*/ setAdditionalProperty(key, value) {
|
|
55148
|
-
this.
|
|
55672
|
+
this.metadata.additionalProperties[key] = value;
|
|
55149
55673
|
}
|
|
55150
55674
|
/**
|
|
55151
55675
|
* Checks whether additional property exists.
|
|
@@ -55154,25 +55678,26 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55154
55678
|
*
|
|
55155
55679
|
* @returns Whether the property exists.
|
|
55156
55680
|
*/ hasAdditionalProperty(key) {
|
|
55157
|
-
return Object.hasOwn(this.
|
|
55681
|
+
return Object.hasOwn(this.metadata.additionalProperties, key);
|
|
55158
55682
|
}
|
|
55159
55683
|
/**
|
|
55160
55684
|
* Removes additional property.
|
|
55161
55685
|
*
|
|
55162
55686
|
* @param key Property key.
|
|
55163
55687
|
*/ removeAdditionalProperty(key) {
|
|
55164
|
-
delete this.
|
|
55688
|
+
delete this.metadata.additionalProperties[key];
|
|
55165
55689
|
}
|
|
55166
55690
|
/**
|
|
55167
|
-
* Serializes the ruleset to a string
|
|
55691
|
+
* Serializes the ruleset to a string: a JSON array of metadata rules
|
|
55692
|
+
* carrying the payload in `metadata.chunk` fragments.
|
|
55168
55693
|
*
|
|
55169
55694
|
* @param pretty Whether to prettify the output.
|
|
55170
55695
|
*
|
|
55171
55696
|
* @returns Serialized ruleset.
|
|
55172
55697
|
*/ serialize(pretty = false) {
|
|
55173
|
-
|
|
55174
|
-
|
|
55175
|
-
|
|
55698
|
+
// The metadata ruleset has no ordinary rules, so no ids are taken.
|
|
55699
|
+
const rules = MetadataRules.create(this.metadata, new Set(), pretty);
|
|
55700
|
+
return serializeJson(rules, pretty);
|
|
55176
55701
|
}
|
|
55177
55702
|
/**
|
|
55178
55703
|
* Deserializes the ruleset from a string.
|
|
@@ -55181,14 +55706,14 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55181
55706
|
*
|
|
55182
55707
|
* @returns Deserialized ruleset.
|
|
55183
55708
|
*
|
|
55184
|
-
* @throws {ValiError} If the metadata fails schema validation.
|
|
55185
55709
|
* @throws {SyntaxError} If `rawJson` is not valid JSON.
|
|
55710
|
+
* @throws {InvalidMetadataChunksError} If the metadata rules are missing
|
|
55711
|
+
* or malformed.
|
|
55712
|
+
* @throws {ValiError} If the payload fails schema validation.
|
|
55186
55713
|
*/ static deserialize(rawJson) {
|
|
55187
|
-
const
|
|
55188
|
-
|
|
55189
|
-
|
|
55190
|
-
}
|
|
55191
|
-
const { metadata: { checksums, additionalProperties } } = v__namespace.parse(metadataRuleValidator, parsed[0]);
|
|
55714
|
+
const rulesetId = getRulesetId(METADATA_RULESET_ID);
|
|
55715
|
+
const { payload } = MetadataRules.read(rulesetId, JSON.parse(rawJson));
|
|
55716
|
+
const { checksums, additionalProperties } = v__namespace.parse(metadataValidator, payload);
|
|
55192
55717
|
return new MetadataRuleset(checksums, additionalProperties);
|
|
55193
55718
|
}
|
|
55194
55719
|
/**
|
|
@@ -55205,14 +55730,14 @@ var getRedirectFilename = function getRedirectFilename(name) {
|
|
|
55205
55730
|
* @note
|
|
55206
55731
|
* Inputs are shallow-cloned so the instance owns its internal state.
|
|
55207
55732
|
*/ constructor(checksums = {}, additionalProperties = {}){
|
|
55208
|
-
this.
|
|
55733
|
+
this.metadata = {
|
|
55209
55734
|
checksums: {
|
|
55210
55735
|
...checksums
|
|
55211
55736
|
},
|
|
55212
55737
|
additionalProperties: {
|
|
55213
55738
|
...additionalProperties
|
|
55214
55739
|
}
|
|
55215
|
-
}
|
|
55740
|
+
};
|
|
55216
55741
|
}
|
|
55217
55742
|
}
|
|
55218
55743
|
|
|
@@ -59404,8 +59929,8 @@ const LOCAL_METADATA_FILE_NAME = 'filters.json';
|
|
|
59404
59929
|
* @param rulesetsPath Path to the rulesets directory.
|
|
59405
59930
|
* @param outputPath Path to save extracted filters.
|
|
59406
59931
|
*
|
|
59407
|
-
* @throws Error if rulesetsPath is not a directory or
|
|
59408
|
-
*
|
|
59932
|
+
* @throws Error if rulesetsPath is not a directory. Read or parse errors of
|
|
59933
|
+
* individual files are logged and the file is skipped.
|
|
59409
59934
|
*/ static async extract(rulesetsPath, outputPath) {
|
|
59410
59935
|
await ensureDir(outputPath);
|
|
59411
59936
|
const rulesetsPaths = await findFiles(rulesetsPath, (filePath)=>filePath.endsWith(RULESET_FILE_EXT));
|
|
@@ -59421,17 +59946,7 @@ const LOCAL_METADATA_FILE_NAME = 'filters.json';
|
|
|
59421
59946
|
continue;
|
|
59422
59947
|
}
|
|
59423
59948
|
const data = await fs$1.readFile(jsonFilePath, 'utf8');
|
|
59424
|
-
const
|
|
59425
|
-
if (!Array.isArray(parsedRuleset) || parsedRuleset.length === 0) {
|
|
59426
|
-
console.log(`Ruleset ${jsonFilePath} is not an array or contains zero elements, skipping.`);
|
|
59427
|
-
continue;
|
|
59428
|
-
}
|
|
59429
|
-
const { metadata } = parsedRuleset[0];
|
|
59430
|
-
if (!metadata) {
|
|
59431
|
-
console.log(`Ruleset ${jsonFilePath} does not contain metadata, skipping.`);
|
|
59432
|
-
continue;
|
|
59433
|
-
}
|
|
59434
|
-
const { filterContent } = metadata;
|
|
59949
|
+
const { filterContent } = parseCompactRuleset(getRulesetId(filterId), JSON.parse(data));
|
|
59435
59950
|
const outputFileName = `filter_${filterId}.txt`;
|
|
59436
59951
|
const outputFilePath = path.join(outputPath, outputFileName);
|
|
59437
59952
|
await fs$1.writeFile(outputFilePath, filterContent);
|