@adguard/dnr-converter 2.1.0 → 2.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.
- package/dist/cli.cjs +305 -53
- package/dist/package.json.js +1 -1
- package/dist/rule-converters/regular-rule-converter.js +12 -2
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -143,7 +143,7 @@ var devDependencies = {
|
|
|
143
143
|
typescript: "catalog:",
|
|
144
144
|
vitest: "catalog:"
|
|
145
145
|
};
|
|
146
|
-
var version = "2.1.
|
|
146
|
+
var version = "2.1.1";
|
|
147
147
|
var packageJson = {
|
|
148
148
|
name: name,
|
|
149
149
|
description: description,
|
|
@@ -490,7 +490,7 @@ if (!('version' in packageJson) || "string" !== 'string' || packageJson.version.
|
|
|
490
490
|
});
|
|
491
491
|
|
|
492
492
|
/*
|
|
493
|
-
* AGTree v4.4.0 (build date:
|
|
493
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
494
494
|
* (c) 2026 Adguard Software Ltd.
|
|
495
495
|
* Released under the MIT license
|
|
496
496
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -612,7 +612,7 @@ if (!('version' in packageJson) || "string" !== 'string' || packageJson.version.
|
|
|
612
612
|
};
|
|
613
613
|
|
|
614
614
|
/*
|
|
615
|
-
* AGTree v4.4.0 (build date:
|
|
615
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
616
616
|
* (c) 2026 Adguard Software Ltd.
|
|
617
617
|
* Released under the MIT license
|
|
618
618
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -727,7 +727,7 @@ const IF = 'if';
|
|
|
727
727
|
const INCLUDE = 'include';
|
|
728
728
|
|
|
729
729
|
/*
|
|
730
|
-
* AGTree v4.4.0 (build date:
|
|
730
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
731
731
|
* (c) 2026 Adguard Software Ltd.
|
|
732
732
|
* Released under the MIT license
|
|
733
733
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -765,7 +765,7 @@ const BASE_MESSAGE = 'Not implemented';
|
|
|
765
765
|
}
|
|
766
766
|
|
|
767
767
|
/*
|
|
768
|
-
* AGTree v4.4.0 (build date:
|
|
768
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
769
769
|
* (c) 2026 Adguard Software Ltd.
|
|
770
770
|
* Released under the MIT license
|
|
771
771
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -979,7 +979,7 @@ const BASE_MESSAGE = 'Not implemented';
|
|
|
979
979
|
}
|
|
980
980
|
|
|
981
981
|
/*
|
|
982
|
-
* AGTree v4.4.0 (build date:
|
|
982
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
983
983
|
* (c) 2026 Adguard Software Ltd.
|
|
984
984
|
* Released under the MIT license
|
|
985
985
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -1594,7 +1594,7 @@ const DOUBLE_QUOTE_MARKER = '"';
|
|
|
1594
1594
|
}
|
|
1595
1595
|
|
|
1596
1596
|
/*
|
|
1597
|
-
* AGTree v4.4.0 (build date:
|
|
1597
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
1598
1598
|
* (c) 2026 Adguard Software Ltd.
|
|
1599
1599
|
* Released under the MIT license
|
|
1600
1600
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -1983,7 +1983,7 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
1983
1983
|
}
|
|
1984
1984
|
|
|
1985
1985
|
/*
|
|
1986
|
-
* AGTree v4.4.0 (build date:
|
|
1986
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
1987
1987
|
* (c) 2026 Adguard Software Ltd.
|
|
1988
1988
|
* Released under the MIT license
|
|
1989
1989
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -2053,7 +2053,7 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
2053
2053
|
};
|
|
2054
2054
|
|
|
2055
2055
|
/*
|
|
2056
|
-
* AGTree v4.4.0 (build date:
|
|
2056
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
2057
2057
|
* (c) 2026 Adguard Software Ltd.
|
|
2058
2058
|
* Released under the MIT license
|
|
2059
2059
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -2772,7 +2772,7 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
2772
2772
|
}
|
|
2773
2773
|
|
|
2774
2774
|
/*
|
|
2775
|
-
* AGTree v4.4.0 (build date:
|
|
2775
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
2776
2776
|
* (c) 2026 Adguard Software Ltd.
|
|
2777
2777
|
* Released under the MIT license
|
|
2778
2778
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -17811,7 +17811,7 @@ function requireSprintf () {
|
|
|
17811
17811
|
var sprintfExports = requireSprintf();
|
|
17812
17812
|
|
|
17813
17813
|
/*
|
|
17814
|
-
* CSSTokenizer v1.3.0 (build date:
|
|
17814
|
+
* CSSTokenizer v1.3.0 (build date: Tue, 17 Nov 2026 07:42:50 GMT)
|
|
17815
17815
|
* (c) 2026 Adguard Software Ltd.
|
|
17816
17816
|
* Released under the MIT license
|
|
17817
17817
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/css-tokenizer#readme
|
|
@@ -19164,6 +19164,261 @@ var sprintfExports = requireSprintf();
|
|
|
19164
19164
|
/**
|
|
19165
19165
|
* @file Custom tokenizing logic for Extended CSS's pseudo-classes
|
|
19166
19166
|
*/ /**
|
|
19167
|
+
* Checks whether the opening parenthesis at the given index starts a pseudo-class
|
|
19168
|
+
* function, e.g. `:has-text(`.
|
|
19169
|
+
*
|
|
19170
|
+
* @param context Reference to the tokenizer context instance.
|
|
19171
|
+
* @param index Index of the opening parenthesis relative to the argument start.
|
|
19172
|
+
*
|
|
19173
|
+
* @returns `true` if the parenthesis follows a pseudo-class name, `false` otherwise.
|
|
19174
|
+
*/ const isPseudoClassFunctionOpening = (context, index)=>{
|
|
19175
|
+
let nameIndex = index - 1;
|
|
19176
|
+
if (!isIdentCodePoint(context.getRelativeCode(nameIndex))) {
|
|
19177
|
+
return false;
|
|
19178
|
+
}
|
|
19179
|
+
while(nameIndex >= 0 && isIdentCodePoint(context.getRelativeCode(nameIndex))){
|
|
19180
|
+
nameIndex -= 1;
|
|
19181
|
+
}
|
|
19182
|
+
return context.getRelativeCode(nameIndex) === 58 /* CodePoint.Colon */ ;
|
|
19183
|
+
};
|
|
19184
|
+
/**
|
|
19185
|
+
* Finds the closing solidus of a regexp literal, if the literal is complete and its
|
|
19186
|
+
* character classes are unambiguous.
|
|
19187
|
+
*
|
|
19188
|
+
* The scan starts right after the opening solidus and stops at the first unescaped
|
|
19189
|
+
* solidus outside a character class. Escapes are read in pairs, so a solidus or a
|
|
19190
|
+
* square bracket preceded by an odd number of reverse solidi is plain text. Parentheses
|
|
19191
|
+
* outside character classes must be balanced, as in a valid regexp; otherwise the
|
|
19192
|
+
* solidus is treated as plain text.
|
|
19193
|
+
*
|
|
19194
|
+
* A right parenthesis inside a character class is treated as literal text, unless the
|
|
19195
|
+
* rest of the class looks like the following selector. That is the case when, after the
|
|
19196
|
+
* parenthesis, an opening parenthesis starts a pseudo-class function, e.g.
|
|
19197
|
+
* `:has-text(/foo[bar):has-text(]/)`, or an opening square bracket has anything but the
|
|
19198
|
+
* parenthesis right before it, e.g. `:has-text(/foo[bar) + a[href="/x]y/"])`. In these
|
|
19199
|
+
* examples the `)` closes the pseudo-class, and the later brackets and the solidus must
|
|
19200
|
+
* not make the argument a regexp. A bracket that immediately follows the parenthesis,
|
|
19201
|
+
* as in `:has-text(/[)[]/)`, stays a part of the class.
|
|
19202
|
+
*
|
|
19203
|
+
* @param context Reference to the tokenizer context instance.
|
|
19204
|
+
* @param start Index of the opening solidus relative to the argument start.
|
|
19205
|
+
* @param limit End of the source range to scan, relative to the argument start. Callers
|
|
19206
|
+
* pass the rest of the source; the literal is used only when a parenthesis closing the
|
|
19207
|
+
* argument follows it.
|
|
19208
|
+
*
|
|
19209
|
+
* @returns Index of the closing solidus relative to the argument start, or `-1` if the
|
|
19210
|
+
* solidus does not open a complete regexp literal.
|
|
19211
|
+
*/ const findRegexpLiteralEnd = (context, start, limit)=>{
|
|
19212
|
+
let inClass = false;
|
|
19213
|
+
let classHasParenthesis = false;
|
|
19214
|
+
let depth = 0;
|
|
19215
|
+
let escaped = false;
|
|
19216
|
+
for(let index = start + 1; index < limit; index += 1){
|
|
19217
|
+
const code = context.getRelativeCode(index);
|
|
19218
|
+
if (escaped) {
|
|
19219
|
+
escaped = false;
|
|
19220
|
+
continue;
|
|
19221
|
+
}
|
|
19222
|
+
if (code === 92 /* CodePoint.ReverseSolidus */ ) {
|
|
19223
|
+
escaped = true;
|
|
19224
|
+
continue;
|
|
19225
|
+
}
|
|
19226
|
+
if (inClass) {
|
|
19227
|
+
if (code === 93 /* CodePoint.RightSquareBracket */ ) {
|
|
19228
|
+
inClass = false;
|
|
19229
|
+
classHasParenthesis = false;
|
|
19230
|
+
} else if (code === 41 /* CodePoint.RightParenthesis */ ) {
|
|
19231
|
+
classHasParenthesis = true;
|
|
19232
|
+
} else if (classHasParenthesis && (code === 40 /* CodePoint.LeftParenthesis */ && isPseudoClassFunctionOpening(context, index) || code === 91 /* CodePoint.LeftSquareBracket */ && context.getRelativeCode(index - 1) !== 41 /* CodePoint.RightParenthesis */ )) {
|
|
19233
|
+
// The class spans what looks like the rest of the selector, so the
|
|
19234
|
+
// parenthesis in it is more likely the pseudo-class closing parenthesis.
|
|
19235
|
+
return -1;
|
|
19236
|
+
}
|
|
19237
|
+
continue;
|
|
19238
|
+
}
|
|
19239
|
+
if (code === 91 /* CodePoint.LeftSquareBracket */ ) {
|
|
19240
|
+
inClass = true;
|
|
19241
|
+
classHasParenthesis = false;
|
|
19242
|
+
} else if (code === 40 /* CodePoint.LeftParenthesis */ ) {
|
|
19243
|
+
depth += 1;
|
|
19244
|
+
} else if (code === 41 /* CodePoint.RightParenthesis */ ) {
|
|
19245
|
+
// An unbalanced parenthesis outside a class is not a valid regexp
|
|
19246
|
+
if (depth === 0) {
|
|
19247
|
+
return -1;
|
|
19248
|
+
}
|
|
19249
|
+
depth -= 1;
|
|
19250
|
+
} else if (code === 47 /* CodePoint.Solidus */ ) {
|
|
19251
|
+
return depth === 0 ? index : -1;
|
|
19252
|
+
}
|
|
19253
|
+
}
|
|
19254
|
+
return -1;
|
|
19255
|
+
};
|
|
19256
|
+
/**
|
|
19257
|
+
* Checks whether the solidus at the given index opens a regexp literal.
|
|
19258
|
+
*
|
|
19259
|
+
* A literal is either the whole argument, e.g. `:has-text(/a/)`, or the value of a
|
|
19260
|
+
* `property: value` argument, e.g. `:matches-css(background-image: /^url\(/)`. Any other
|
|
19261
|
+
* solidus is plain text, so arguments such as `:has-text(http://example.com/a)` keep
|
|
19262
|
+
* their previous behavior.
|
|
19263
|
+
*
|
|
19264
|
+
* @param context Reference to the tokenizer context instance.
|
|
19265
|
+
* @param index Index of the solidus relative to the argument start.
|
|
19266
|
+
*
|
|
19267
|
+
* @returns `true` if the solidus may open a regexp literal, `false` otherwise.
|
|
19268
|
+
*/ const isRegexpLiteralStart = (context, index)=>{
|
|
19269
|
+
if (index === 0) {
|
|
19270
|
+
return true;
|
|
19271
|
+
}
|
|
19272
|
+
let previousIndex = index - 1;
|
|
19273
|
+
while(previousIndex >= 0 && isWhitespace(context.getRelativeCode(previousIndex) ?? 0)){
|
|
19274
|
+
previousIndex -= 1;
|
|
19275
|
+
}
|
|
19276
|
+
return context.getRelativeCode(previousIndex) === 58 /* CodePoint.Colon */ ;
|
|
19277
|
+
};
|
|
19278
|
+
/**
|
|
19279
|
+
* Finds the closing parenthesis of the pseudo-class argument after a regexp literal.
|
|
19280
|
+
*
|
|
19281
|
+
* The literal may be followed by more text of the same argument, e.g.
|
|
19282
|
+
* `:has-text(/a[)]b/ + a)`, so the search continues from the literal end and returns
|
|
19283
|
+
* the first unescaped parenthesis that closes the argument. If the rest of the source
|
|
19284
|
+
* has no such parenthesis, the literal is not a part of the argument, e.g.
|
|
19285
|
+
* `:has-text(/a[)]b/ + a[href="/x]y/"]`.
|
|
19286
|
+
*
|
|
19287
|
+
* @param context Reference to the tokenizer context instance.
|
|
19288
|
+
* @param literalEnd Index of the closing solidus relative to the argument start.
|
|
19289
|
+
* @param length Length of the source after the argument start.
|
|
19290
|
+
*
|
|
19291
|
+
* @returns Index of the closing parenthesis relative to the argument start, or `-1` if
|
|
19292
|
+
* the parenthesis does not follow the literal.
|
|
19293
|
+
*/ const findClosingParenAfterLiteral = (context, literalEnd, length)=>{
|
|
19294
|
+
let depth = 0;
|
|
19295
|
+
let escaped = false;
|
|
19296
|
+
for(let index = literalEnd + 1; index < length; index += 1){
|
|
19297
|
+
const code = context.getRelativeCode(index);
|
|
19298
|
+
if (escaped) {
|
|
19299
|
+
escaped = false;
|
|
19300
|
+
continue;
|
|
19301
|
+
}
|
|
19302
|
+
if (code === 92 /* CodePoint.ReverseSolidus */ ) {
|
|
19303
|
+
escaped = true;
|
|
19304
|
+
continue;
|
|
19305
|
+
}
|
|
19306
|
+
if (code === 40 /* CodePoint.LeftParenthesis */ ) {
|
|
19307
|
+
depth += 1;
|
|
19308
|
+
continue;
|
|
19309
|
+
}
|
|
19310
|
+
if (code === 41 /* CodePoint.RightParenthesis */ ) {
|
|
19311
|
+
if (depth === 0) {
|
|
19312
|
+
return index;
|
|
19313
|
+
}
|
|
19314
|
+
depth -= 1;
|
|
19315
|
+
}
|
|
19316
|
+
}
|
|
19317
|
+
return -1;
|
|
19318
|
+
};
|
|
19319
|
+
/**
|
|
19320
|
+
* Finds the end of the raw argument of an Extended CSS pseudo-class.
|
|
19321
|
+
*
|
|
19322
|
+
* The argument ends at the first unescaped right parenthesis which closes it. A
|
|
19323
|
+
* parenthesis inside a regexp character class does not close the argument when a
|
|
19324
|
+
* complete literal spans that parenthesis and another parenthesis that closes the
|
|
19325
|
+
* argument follows the literal. When the class-blind scan finds no closing parenthesis
|
|
19326
|
+
* at all, a complete literal followed by one is used instead. Otherwise the argument
|
|
19327
|
+
* keeps its class-blind end, so a later part of the selector cannot turn a plain-text
|
|
19328
|
+
* argument into a regexp.
|
|
19329
|
+
*
|
|
19330
|
+
* @param context Reference to the tokenizer context instance, positioned at the start
|
|
19331
|
+
* of the argument.
|
|
19332
|
+
*
|
|
19333
|
+
* @returns Number of code points in the argument, i.e. the offset of its closing
|
|
19334
|
+
* parenthesis relative to the argument start. If the parenthesis is missing, the rest
|
|
19335
|
+
* of the source is returned.
|
|
19336
|
+
*/ const findArgumentEnd = (context)=>{
|
|
19337
|
+
const length = context.length - context.offset;
|
|
19338
|
+
// Find the first right parenthesis that closes the argument when character classes
|
|
19339
|
+
// are not taken into account. This is the previous behavior, used as a fallback.
|
|
19340
|
+
let depth = 0;
|
|
19341
|
+
let escaped = false;
|
|
19342
|
+
let candidate = length;
|
|
19343
|
+
for(let index = 0; index < length; index += 1){
|
|
19344
|
+
const code = context.getRelativeCode(index);
|
|
19345
|
+
if (escaped) {
|
|
19346
|
+
escaped = false;
|
|
19347
|
+
continue;
|
|
19348
|
+
}
|
|
19349
|
+
if (code === 92 /* CodePoint.ReverseSolidus */ ) {
|
|
19350
|
+
escaped = true;
|
|
19351
|
+
continue;
|
|
19352
|
+
}
|
|
19353
|
+
if (code === 40 /* CodePoint.LeftParenthesis */ ) {
|
|
19354
|
+
depth += 1;
|
|
19355
|
+
continue;
|
|
19356
|
+
}
|
|
19357
|
+
if (code === 41 /* CodePoint.RightParenthesis */ ) {
|
|
19358
|
+
if (depth === 0) {
|
|
19359
|
+
candidate = index;
|
|
19360
|
+
break;
|
|
19361
|
+
}
|
|
19362
|
+
depth -= 1;
|
|
19363
|
+
}
|
|
19364
|
+
}
|
|
19365
|
+
// Look for a complete regexp literal that starts before the candidate and spans it,
|
|
19366
|
+
// i.e. the candidate is inside a character class of the literal. Only then the
|
|
19367
|
+
// argument may end after the literal, at the parenthesis that follows it. If there
|
|
19368
|
+
// is no candidate, the class-blind scan saw unbalanced parentheses, so a complete
|
|
19369
|
+
// literal followed by the closing parenthesis is used as well.
|
|
19370
|
+
const hasCandidate = candidate < length;
|
|
19371
|
+
let index = 0;
|
|
19372
|
+
let quote = null;
|
|
19373
|
+
escaped = false;
|
|
19374
|
+
while(index < length){
|
|
19375
|
+
const code = context.getRelativeCode(index);
|
|
19376
|
+
if (escaped) {
|
|
19377
|
+
escaped = false;
|
|
19378
|
+
index += 1;
|
|
19379
|
+
continue;
|
|
19380
|
+
}
|
|
19381
|
+
if (code === 92 /* CodePoint.ReverseSolidus */ ) {
|
|
19382
|
+
escaped = true;
|
|
19383
|
+
index += 1;
|
|
19384
|
+
continue;
|
|
19385
|
+
}
|
|
19386
|
+
// Skip quoted text, where a colon does not start a `property: value` argument
|
|
19387
|
+
if (quote !== null) {
|
|
19388
|
+
if (code === quote) {
|
|
19389
|
+
quote = null;
|
|
19390
|
+
}
|
|
19391
|
+
index += 1;
|
|
19392
|
+
continue;
|
|
19393
|
+
}
|
|
19394
|
+
if (code === 39 /* CodePoint.Apostrophe */ || code === 34 /* CodePoint.QuotationMark */ ) {
|
|
19395
|
+
quote = code;
|
|
19396
|
+
index += 1;
|
|
19397
|
+
continue;
|
|
19398
|
+
}
|
|
19399
|
+
if (code !== 47 /* CodePoint.Solidus */ || !isRegexpLiteralStart(context, index)) {
|
|
19400
|
+
index += 1;
|
|
19401
|
+
continue;
|
|
19402
|
+
}
|
|
19403
|
+
const literalEnd = findRegexpLiteralEnd(context, index, length);
|
|
19404
|
+
if (literalEnd < 0) {
|
|
19405
|
+
index += 1;
|
|
19406
|
+
continue;
|
|
19407
|
+
}
|
|
19408
|
+
if (hasCandidate && literalEnd < candidate) {
|
|
19409
|
+
// The literal ends before the candidate, so it cannot change the argument end
|
|
19410
|
+
index = literalEnd + 1;
|
|
19411
|
+
continue;
|
|
19412
|
+
}
|
|
19413
|
+
const argumentEnd = findClosingParenAfterLiteral(context, literalEnd, length);
|
|
19414
|
+
if (argumentEnd >= 0) {
|
|
19415
|
+
return argumentEnd;
|
|
19416
|
+
}
|
|
19417
|
+
break;
|
|
19418
|
+
}
|
|
19419
|
+
return candidate;
|
|
19420
|
+
};
|
|
19421
|
+
/**
|
|
19167
19422
|
* Generic handler for the Extended CSS's pseudo-classes
|
|
19168
19423
|
*
|
|
19169
19424
|
* @param context Reference to the tokenizer context instance
|
|
@@ -19188,31 +19443,18 @@ var sprintfExports = requireSprintf();
|
|
|
19188
19443
|
// We simply abort the custom handler
|
|
19189
19444
|
return;
|
|
19190
19445
|
}
|
|
19191
|
-
// Otherwise, we need to find the closing parenthesis based on the parenthesis balance
|
|
19192
|
-
// Parenthesis balance: 1, because we start after the opening parenthesis:
|
|
19193
|
-
// :contains(param)
|
|
19194
|
-
// ^ we starts from here, so we already have 1 open parenthesis
|
|
19195
|
-
let balance = 1;
|
|
19196
19446
|
// Don't forget to report already consumed whitespace chars as delim-tokens (if any)
|
|
19197
19447
|
// Note: we handle the parameter characters as delim-tokens, this is why we don't need to report them here
|
|
19198
19448
|
// as whitespace-tokens
|
|
19199
19449
|
for(let i = start; i < context.offset; i += 1){
|
|
19200
19450
|
context.onToken(TokenType.Delim, i, i + 1, undefined, context.stop);
|
|
19201
19451
|
}
|
|
19202
|
-
//
|
|
19203
|
-
|
|
19204
|
-
|
|
19205
|
-
|
|
19206
|
-
|
|
19207
|
-
|
|
19208
|
-
// If we find an unescaped closing parenthesis, we decrease the balance
|
|
19209
|
-
balance -= 1;
|
|
19210
|
-
// If the balance is 0, it means that we found the closing parenthesis
|
|
19211
|
-
if (balance === 0) {
|
|
19212
|
-
break;
|
|
19213
|
-
}
|
|
19214
|
-
}
|
|
19215
|
-
// Consume the current character as a delim-token
|
|
19452
|
+
// Parentheses inside a regexp character class are literal characters, so they must
|
|
19453
|
+
// not close the pseudo-class. The argument end is found before consuming anything.
|
|
19454
|
+
const argumentLength = findArgumentEnd(context);
|
|
19455
|
+
// Consume the argument as delim-tokens, leaving the closing parenthesis to the
|
|
19456
|
+
// standard tokenizer
|
|
19457
|
+
for(let argumentIndex = 0; argumentIndex < argumentLength && !context.isEof(); argumentIndex += 1){
|
|
19216
19458
|
context.consumeTrivialToken(TokenType.Delim);
|
|
19217
19459
|
}
|
|
19218
19460
|
};
|
|
@@ -21674,7 +21916,7 @@ var lib = JSON5;
|
|
|
21674
21916
|
}
|
|
21675
21917
|
|
|
21676
21918
|
/*
|
|
21677
|
-
* AGTree v4.4.0 (build date:
|
|
21919
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
21678
21920
|
* (c) 2026 Adguard Software Ltd.
|
|
21679
21921
|
* Released under the MIT license
|
|
21680
21922
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -21767,7 +22009,7 @@ var lib = JSON5;
|
|
|
21767
22009
|
*/ const REMOVE_VALUE = 'true';
|
|
21768
22010
|
|
|
21769
22011
|
/*
|
|
21770
|
-
* AGTree v4.4.0 (build date:
|
|
22012
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
21771
22013
|
* (c) 2026 Adguard Software Ltd.
|
|
21772
22014
|
* Released under the MIT license
|
|
21773
22015
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -23148,7 +23390,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
23148
23390
|
}
|
|
23149
23391
|
|
|
23150
23392
|
/*
|
|
23151
|
-
* AGTree v4.4.0 (build date:
|
|
23393
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
23152
23394
|
* (c) 2026 Adguard Software Ltd.
|
|
23153
23395
|
* Released under the MIT license
|
|
23154
23396
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -23533,7 +23775,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
23533
23775
|
}
|
|
23534
23776
|
|
|
23535
23777
|
/*
|
|
23536
|
-
* AGTree v4.4.0 (build date:
|
|
23778
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
23537
23779
|
* (c) 2026 Adguard Software Ltd.
|
|
23538
23780
|
* Released under the MIT license
|
|
23539
23781
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -29474,7 +29716,7 @@ var isIp = /*@__PURE__*/getDefaultExportFromCjs(isIpExports);
|
|
|
29474
29716
|
}
|
|
29475
29717
|
|
|
29476
29718
|
/*
|
|
29477
|
-
* AGTree v4.4.0 (build date:
|
|
29719
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
29478
29720
|
* (c) 2026 Adguard Software Ltd.
|
|
29479
29721
|
* Released under the MIT license
|
|
29480
29722
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -29495,7 +29737,7 @@ var isIp = /*@__PURE__*/getDefaultExportFromCjs(isIpExports);
|
|
|
29495
29737
|
}
|
|
29496
29738
|
|
|
29497
29739
|
/*
|
|
29498
|
-
* AGTree v4.4.0 (build date:
|
|
29740
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
29499
29741
|
* (c) 2026 Adguard Software Ltd.
|
|
29500
29742
|
* Released under the MIT license
|
|
29501
29743
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -29543,7 +29785,7 @@ var isIp = /*@__PURE__*/getDefaultExportFromCjs(isIpExports);
|
|
|
29543
29785
|
};
|
|
29544
29786
|
|
|
29545
29787
|
/*
|
|
29546
|
-
* AGTree v4.4.0 (build date:
|
|
29788
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
29547
29789
|
* (c) 2026 Adguard Software Ltd.
|
|
29548
29790
|
* Released under the MIT license
|
|
29549
29791
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -29926,7 +30168,7 @@ const GenericPlatform = {
|
|
|
29926
30168
|
}
|
|
29927
30169
|
|
|
29928
30170
|
/*
|
|
29929
|
-
* AGTree v4.4.0 (build date:
|
|
30171
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
29930
30172
|
* (c) 2026 Adguard Software Ltd.
|
|
29931
30173
|
* Released under the MIT license
|
|
29932
30174
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -48120,7 +48362,7 @@ var cloneDeep = /*@__PURE__*/getDefaultExportFromCjs(cloneDeepExports);
|
|
|
48120
48362
|
}
|
|
48121
48363
|
|
|
48122
48364
|
/*
|
|
48123
|
-
* AGTree v4.4.0 (build date:
|
|
48365
|
+
* AGTree v4.4.0 (build date: Tue, 17 Nov 2026 07:43:08 GMT)
|
|
48124
48366
|
* (c) 2026 Adguard Software Ltd.
|
|
48125
48367
|
* Released under the MIT license
|
|
48126
48368
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -49321,30 +49563,31 @@ const ERROR_MESSAGES$1 = {
|
|
|
49321
49563
|
* Handles special pseudo-class selectors during uBlock to AdGuard conversion:
|
|
49322
49564
|
* - `:has-text(text)` -> `:contains(text)`
|
|
49323
49565
|
* direct conversion, no changes to argument
|
|
49566
|
+
* - `:contains(text)` -> `:contains(text)`
|
|
49567
|
+
* kept as-is, no changes to argument. The uBlock Origin parser
|
|
49568
|
+
* accepts `:contains()` in `##^` rules and normalizes it to
|
|
49569
|
+
* `:has-text()`.
|
|
49324
49570
|
* - `:min-text-length(min)` -> `:contains(/^(?=.{min,MAX_CONVERSION_DEFAULT}$).*\/s)`
|
|
49325
49571
|
* converts to a length-matching regular expression.
|
|
49326
49572
|
*
|
|
49327
|
-
* The converter rejects
|
|
49328
|
-
*
|
|
49329
|
-
*
|
|
49330
|
-
* normalizes it to `:has-text()`. Only the `-abp-*` names need the `#?#`
|
|
49331
|
-
* syntax there, so uBlock rejects `##^div:-abp-contains(foo)`. The
|
|
49332
|
-
* `:contains()` rejection is the converter's own rule, not a uBlock
|
|
49333
|
-
* limitation. Converting a valid uBlock `:contains()` rule to AdGuard is
|
|
49334
|
-
* a separate task.
|
|
49573
|
+
* The converter rejects `:-abp-contains()` in uBlock rules as mixed
|
|
49574
|
+
* syntax, because only the `-abp-*` names need the `#?#` syntax there,
|
|
49575
|
+
* so uBlock rejects `##^div:-abp-contains(foo)`.
|
|
49335
49576
|
*
|
|
49336
49577
|
* @param name Name of the special pseudo-class selector.
|
|
49337
49578
|
* @param argument Argument of the special pseudo-class selector.
|
|
49338
49579
|
*
|
|
49339
49580
|
* @returns A {@link SimpleSelector} to add to the current complex selector.
|
|
49340
49581
|
*
|
|
49341
|
-
* @throws If
|
|
49342
|
-
* rule (mixed syntax).
|
|
49582
|
+
* @throws If `:-abp-contains()` is found in a uBlock rule (mixed syntax).
|
|
49343
49583
|
*/ static convertSpecialPseudoClassSelectorUboToAdg(name, argument) {
|
|
49344
49584
|
switch(name){
|
|
49345
49585
|
// `:has-text(text)` -> `:contains(text)`
|
|
49346
49586
|
// direct conversion, no changes to argument
|
|
49587
|
+
// `:contains(text)` is accepted by uBlock Origin in `##^` rules,
|
|
49588
|
+
// so it is kept as-is; the name is a valid AdGuard spelling too
|
|
49347
49589
|
case UboPseudoClasses.HasText:
|
|
49590
|
+
case AdgPseudoClasses.Contains:
|
|
49348
49591
|
{
|
|
49349
49592
|
return HtmlRuleConverter.getPseudoClassSelectorNode(AdgPseudoClasses.Contains, argument);
|
|
49350
49593
|
}
|
|
@@ -49363,8 +49606,7 @@ const ERROR_MESSAGES$1 = {
|
|
|
49363
49606
|
}
|
|
49364
49607
|
return HtmlRuleConverter.getPseudoClassSelectorNode(AdgPseudoClasses.Contains, RegExpUtils.getLengthRegexp(minLength, ADG_HTML_CONVERSION_MAX_LENGTH));
|
|
49365
49608
|
}
|
|
49366
|
-
// Throw an error if the AdGuard-
|
|
49367
|
-
case AdgPseudoClasses.Contains:
|
|
49609
|
+
// Throw an error if the AdGuard-only alias is found in uBlock rule
|
|
49368
49610
|
case AdgPseudoClasses.AbpContains:
|
|
49369
49611
|
{
|
|
49370
49612
|
throw new RuleConversionError(sprintfExports.sprintf(ERROR_MESSAGES.INVALID_RULE, ERROR_MESSAGES.MIXED_SYNTAX_ADG_UBO));
|
|
@@ -54764,10 +55006,16 @@ name)=>{
|
|
|
54764
55006
|
const prefix = condition.urlFilter.slice(0, -ADBLOCK_URL_SEPARATOR.length);
|
|
54765
55007
|
const hasDomainAnchor = prefix.startsWith(ADBLOCK_URL_START);
|
|
54766
55008
|
const authority = hasDomainAnchor ? prefix.slice(ADBLOCK_URL_START.length).split('/')[0] : '';
|
|
54767
|
-
|
|
55009
|
+
// The trailing separator can take the query delimiter only when the pattern ends
|
|
55010
|
+
// inside the path. After a bare host it matches the `/` or the port colon,
|
|
55011
|
+
// so the native URL filter already finds the first parameter there.
|
|
55012
|
+
const hasPath = prefix.replace(RegularRuleConverter.ANCHORED_PATTERN_START, '').includes('/');
|
|
55013
|
+
if (useRemoveParamRegex && condition.urlFilter.endsWith(ADBLOCK_URL_SEPARATOR) && prefix.startsWith('|') && hasPath && !/[*?#^]/.test(prefix) && (!hasDomainAnchor || authority.length > 0 && !authority.includes('@'))) {
|
|
54768
55014
|
// Share the trailing separator with the query delimiter when the parameter is first.
|
|
54769
55015
|
// Anchoring keeps this delimiter at the actual query boundary.
|
|
54770
55016
|
// Unanchored patterns can match inside the query and retain native URL-filter matching.
|
|
55017
|
+
// Patterns without a path keep it too: a filter list has thousands of them,
|
|
55018
|
+
// and DNR allows only 1000 regexp rules.
|
|
54771
55019
|
const patternRegexp = RegExpUtils.patternToRegexp(condition.urlFilter);
|
|
54772
55020
|
let prefixRegexp = patternRegexp.slice(0, -ADBLOCK_URL_SEPARATOR_REGEX.length);
|
|
54773
55021
|
if (hasDomainAnchor) {
|
|
@@ -54778,7 +55026,7 @@ name)=>{
|
|
|
54778
55026
|
const paramNameRegexp = paramRegexp.slice(ADBLOCK_URL_SEPARATOR_REGEX.length);
|
|
54779
55027
|
// DNR matches ASCII-serialized URLs. Bound classes to ASCII to keep RE2 compilation small.
|
|
54780
55028
|
const pathSeparator = '[^[:^ascii:] a-zA-Z0-9.%_?#-]';
|
|
54781
|
-
const pathTail =
|
|
55029
|
+
const pathTail = `(?:${pathSeparator}[^[:^ascii:]?#]*)?`;
|
|
54782
55030
|
condition.regexFilter = `${prefixRegexp}${pathTail}` + `\\?(?:[^[:^ascii:]#]*&)?${paramNameRegexp}`;
|
|
54783
55031
|
delete condition.urlFilter;
|
|
54784
55032
|
} else {
|
|
@@ -55368,6 +55616,10 @@ name)=>{
|
|
|
55368
55616
|
'https:/',
|
|
55369
55617
|
'://'
|
|
55370
55618
|
];
|
|
55619
|
+
/**
|
|
55620
|
+
* Start of an anchored pattern: the `|` or `||` anchor and an optional
|
|
55621
|
+
* scheme. What follows it is the host and, after the first `/`, the path.
|
|
55622
|
+
*/ RegularRuleConverter.ANCHORED_PATTERN_START = /^\|{1,2}(?:[a-z][a-z0-9+.-]*:\/\/)?/i;
|
|
55371
55623
|
|
|
55372
55624
|
/**
|
|
55373
55625
|
* Describes how to convert `$csp` rules.
|
package/dist/package.json.js
CHANGED
|
@@ -592,10 +592,16 @@ import { UnexpectedConversionError } from '../errors/conversion-errors/unexpecte
|
|
|
592
592
|
const prefix = condition.urlFilter.slice(0, -ADBLOCK_URL_SEPARATOR.length);
|
|
593
593
|
const hasDomainAnchor = prefix.startsWith(ADBLOCK_URL_START);
|
|
594
594
|
const authority = hasDomainAnchor ? prefix.slice(ADBLOCK_URL_START.length).split('/')[0] : '';
|
|
595
|
-
|
|
595
|
+
// The trailing separator can take the query delimiter only when the pattern ends
|
|
596
|
+
// inside the path. After a bare host it matches the `/` or the port colon,
|
|
597
|
+
// so the native URL filter already finds the first parameter there.
|
|
598
|
+
const hasPath = prefix.replace(RegularRuleConverter.ANCHORED_PATTERN_START, '').includes('/');
|
|
599
|
+
if (useRemoveParamRegex && condition.urlFilter.endsWith(ADBLOCK_URL_SEPARATOR) && prefix.startsWith('|') && hasPath && !/[*?#^]/.test(prefix) && (!hasDomainAnchor || authority.length > 0 && !authority.includes('@'))) {
|
|
596
600
|
// Share the trailing separator with the query delimiter when the parameter is first.
|
|
597
601
|
// Anchoring keeps this delimiter at the actual query boundary.
|
|
598
602
|
// Unanchored patterns can match inside the query and retain native URL-filter matching.
|
|
603
|
+
// Patterns without a path keep it too: a filter list has thousands of them,
|
|
604
|
+
// and DNR allows only 1000 regexp rules.
|
|
599
605
|
const patternRegexp = RegExpUtils.patternToRegexp(condition.urlFilter);
|
|
600
606
|
let prefixRegexp = patternRegexp.slice(0, -ADBLOCK_URL_SEPARATOR_REGEX.length);
|
|
601
607
|
if (hasDomainAnchor) {
|
|
@@ -606,7 +612,7 @@ import { UnexpectedConversionError } from '../errors/conversion-errors/unexpecte
|
|
|
606
612
|
const paramNameRegexp = paramRegexp.slice(ADBLOCK_URL_SEPARATOR_REGEX.length);
|
|
607
613
|
// DNR matches ASCII-serialized URLs. Bound classes to ASCII to keep RE2 compilation small.
|
|
608
614
|
const pathSeparator = '[^[:^ascii:] a-zA-Z0-9.%_?#-]';
|
|
609
|
-
const pathTail =
|
|
615
|
+
const pathTail = `(?:${pathSeparator}[^[:^ascii:]?#]*)?`;
|
|
610
616
|
condition.regexFilter = `${prefixRegexp}${pathTail}` + `\\?(?:[^[:^ascii:]#]*&)?${paramNameRegexp}`;
|
|
611
617
|
delete condition.urlFilter;
|
|
612
618
|
} else {
|
|
@@ -1196,5 +1202,9 @@ import { UnexpectedConversionError } from '../errors/conversion-errors/unexpecte
|
|
|
1196
1202
|
'https:/',
|
|
1197
1203
|
'://'
|
|
1198
1204
|
];
|
|
1205
|
+
/**
|
|
1206
|
+
* Start of an anchored pattern: the `|` or `||` anchor and an optional
|
|
1207
|
+
* scheme. What follows it is the host and, after the first `/`, the path.
|
|
1208
|
+
*/ RegularRuleConverter.ANCHORED_PATTERN_START = /^\|{1,2}(?:[a-z][a-z0-9+.-]*:\/\/)?/i;
|
|
1199
1209
|
|
|
1200
1210
|
export { RegularRuleConverter };
|
package/package.json
CHANGED
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"@adguard/eslint-plugin-logger-context": "^1.0.1",
|
|
98
98
|
"@adguard/tsurlfilter": "^6.1.0"
|
|
99
99
|
},
|
|
100
|
-
"version": "2.1.
|
|
100
|
+
"version": "2.1.1",
|
|
101
101
|
"scripts": {
|
|
102
102
|
"lint": "pnpm lint:code && pnpm lint:types && pnpm lint:md",
|
|
103
103
|
"lint:code": "eslint --cache --ignore-path .gitignore .",
|