@adguard/dnr-converter 1.1.1 → 1.1.2
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 +370 -370
- package/dist/package.json.js +1 -1
- package/package.json +6 -6
package/dist/cli.cjs
CHANGED
|
@@ -30,7 +30,7 @@ function _interopNamespaceDefault(e) {
|
|
|
30
30
|
|
|
31
31
|
var v__namespace = /*#__PURE__*/_interopNamespaceDefault(v);
|
|
32
32
|
|
|
33
|
-
var version = "1.1.
|
|
33
|
+
var version = "1.1.2";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Version of the `@adguard/dnr-converter` package.
|
|
@@ -656,7 +656,7 @@ var version = "1.1.1";
|
|
|
656
656
|
});
|
|
657
657
|
|
|
658
658
|
/*
|
|
659
|
-
* AGTree v4.2.1 (build date:
|
|
659
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
660
660
|
* (c) 2026 Adguard Software Ltd.
|
|
661
661
|
* Released under the MIT license
|
|
662
662
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -682,7 +682,7 @@ var version = "1.1.1";
|
|
|
682
682
|
}
|
|
683
683
|
|
|
684
684
|
/*
|
|
685
|
-
* AGTree v4.2.1 (build date:
|
|
685
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
686
686
|
* (c) 2026 Adguard Software Ltd.
|
|
687
687
|
* Released under the MIT license
|
|
688
688
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -804,7 +804,7 @@ var version = "1.1.1";
|
|
|
804
804
|
};
|
|
805
805
|
|
|
806
806
|
/*
|
|
807
|
-
* AGTree v4.2.1 (build date:
|
|
807
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
808
808
|
* (c) 2026 Adguard Software Ltd.
|
|
809
809
|
* Released under the MIT license
|
|
810
810
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -874,7 +874,7 @@ var version = "1.1.1";
|
|
|
874
874
|
};
|
|
875
875
|
|
|
876
876
|
/*
|
|
877
|
-
* AGTree v4.2.1 (build date:
|
|
877
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
878
878
|
* (c) 2026 Adguard Software Ltd.
|
|
879
879
|
* Released under the MIT license
|
|
880
880
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -916,7 +916,7 @@ const BASE_MESSAGE = 'Not implemented';
|
|
|
916
916
|
}
|
|
917
917
|
|
|
918
918
|
/*
|
|
919
|
-
* AGTree v4.2.1 (build date:
|
|
919
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
920
920
|
* (c) 2026 Adguard Software Ltd.
|
|
921
921
|
* Released under the MIT license
|
|
922
922
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -936,7 +936,7 @@ const BASE_MESSAGE = 'Not implemented';
|
|
|
936
936
|
});
|
|
937
937
|
|
|
938
938
|
/*
|
|
939
|
-
* AGTree v4.2.1 (build date:
|
|
939
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
940
940
|
* (c) 2026 Adguard Software Ltd.
|
|
941
941
|
* Released under the MIT license
|
|
942
942
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -1731,7 +1731,7 @@ const DOUBLE_QUOTE_MARKER = '"';
|
|
|
1731
1731
|
}
|
|
1732
1732
|
|
|
1733
1733
|
/*
|
|
1734
|
-
* AGTree v4.2.1 (build date:
|
|
1734
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
1735
1735
|
* (c) 2026 Adguard Software Ltd.
|
|
1736
1736
|
* Released under the MIT license
|
|
1737
1737
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -4479,7 +4479,7 @@ function requireSprintf () {
|
|
|
4479
4479
|
var sprintfExports = requireSprintf();
|
|
4480
4480
|
|
|
4481
4481
|
/*
|
|
4482
|
-
* CSSTokenizer v1.2.0 (build date:
|
|
4482
|
+
* CSSTokenizer v1.2.0 (build date: Tue, 25 Aug 2026 03:14:32 GMT)
|
|
4483
4483
|
* (c) 2026 Adguard Software Ltd.
|
|
4484
4484
|
* Released under the MIT license
|
|
4485
4485
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/css-tokenizer#readme
|
|
@@ -6076,7 +6076,7 @@ const XPATH_HASH = 196571984; // getStringHash('xpath')
|
|
|
6076
6076
|
};
|
|
6077
6077
|
|
|
6078
6078
|
/*
|
|
6079
|
-
* AGTree v4.2.1 (build date:
|
|
6079
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
6080
6080
|
* (c) 2026 Adguard Software Ltd.
|
|
6081
6081
|
* Released under the MIT license
|
|
6082
6082
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -6090,7 +6090,7 @@ const XPATH_HASH = 196571984; // getStringHash('xpath')
|
|
|
6090
6090
|
};
|
|
6091
6091
|
|
|
6092
6092
|
/*
|
|
6093
|
-
* AGTree v4.2.1 (build date:
|
|
6093
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
6094
6094
|
* (c) 2026 Adguard Software Ltd.
|
|
6095
6095
|
* Released under the MIT license
|
|
6096
6096
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -6181,7 +6181,7 @@ const XPATH_HASH = 196571984; // getStringHash('xpath')
|
|
|
6181
6181
|
*/ const REMOVE_VALUE = 'true';
|
|
6182
6182
|
|
|
6183
6183
|
/*
|
|
6184
|
-
* AGTree v4.2.1 (build date:
|
|
6184
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
6185
6185
|
* (c) 2026 Adguard Software Ltd.
|
|
6186
6186
|
* Released under the MIT license
|
|
6187
6187
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -8223,7 +8223,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
8223
8223
|
}
|
|
8224
8224
|
|
|
8225
8225
|
/*
|
|
8226
|
-
* AGTree v4.2.1 (build date:
|
|
8226
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
8227
8227
|
* (c) 2026 Adguard Software Ltd.
|
|
8228
8228
|
* Released under the MIT license
|
|
8229
8229
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -8832,7 +8832,7 @@ const ERROR_MESSAGES$6 = {
|
|
|
8832
8832
|
}
|
|
8833
8833
|
|
|
8834
8834
|
/*
|
|
8835
|
-
* AGTree v4.2.1 (build date:
|
|
8835
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
8836
8836
|
* (c) 2026 Adguard Software Ltd.
|
|
8837
8837
|
* Released under the MIT license
|
|
8838
8838
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -23868,7 +23868,7 @@ function getDomain(url, options = {}) {
|
|
|
23868
23868
|
}
|
|
23869
23869
|
|
|
23870
23870
|
/*
|
|
23871
|
-
* AGTree v4.2.1 (build date:
|
|
23871
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
23872
23872
|
* (c) 2026 Adguard Software Ltd.
|
|
23873
23873
|
* Released under the MIT license
|
|
23874
23874
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -23889,7 +23889,7 @@ function getDomain(url, options = {}) {
|
|
|
23889
23889
|
}
|
|
23890
23890
|
|
|
23891
23891
|
/*
|
|
23892
|
-
* AGTree v4.2.1 (build date:
|
|
23892
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
23893
23893
|
* (c) 2026 Adguard Software Ltd.
|
|
23894
23894
|
* Released under the MIT license
|
|
23895
23895
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -23937,7 +23937,7 @@ function getDomain(url, options = {}) {
|
|
|
23937
23937
|
};
|
|
23938
23938
|
|
|
23939
23939
|
/*
|
|
23940
|
-
* AGTree v4.2.1 (build date:
|
|
23940
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
23941
23941
|
* (c) 2026 Adguard Software Ltd.
|
|
23942
23942
|
* Released under the MIT license
|
|
23943
23943
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -24320,7 +24320,7 @@ const GenericPlatform = {
|
|
|
24320
24320
|
}
|
|
24321
24321
|
|
|
24322
24322
|
/*
|
|
24323
|
-
* AGTree v4.2.1 (build date:
|
|
24323
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
24324
24324
|
* (c) 2026 Adguard Software Ltd.
|
|
24325
24325
|
* Released under the MIT license
|
|
24326
24326
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -42106,357 +42106,6 @@ const ABP_RESOURCE_PREFIX_LENGTH = ABP_RESOURCE_PREFIX.length;
|
|
|
42106
42106
|
* Compatibility table instance for scriptlets.
|
|
42107
42107
|
*/ const scriptletsCompatibilityTable = new ScriptletsCompatibilityTable(scriptletsCompatibilityTableData);
|
|
42108
42108
|
|
|
42109
|
-
var globToRegexp;
|
|
42110
|
-
var hasRequiredGlobToRegexp;
|
|
42111
|
-
|
|
42112
|
-
function requireGlobToRegexp () {
|
|
42113
|
-
if (hasRequiredGlobToRegexp) return globToRegexp;
|
|
42114
|
-
hasRequiredGlobToRegexp = 1;
|
|
42115
|
-
globToRegexp = function(glob, opts) {
|
|
42116
|
-
if (typeof glob !== 'string') {
|
|
42117
|
-
throw new TypeError('Expected a string');
|
|
42118
|
-
}
|
|
42119
|
-
var str = String(glob);
|
|
42120
|
-
// The regexp we are building, as a string.
|
|
42121
|
-
var reStr = "";
|
|
42122
|
-
// Whether we are matching so called "extended" globs (like bash) and should
|
|
42123
|
-
// support single character matching, matching ranges of characters, group
|
|
42124
|
-
// matching, etc.
|
|
42125
|
-
var extended = opts ? !!opts.extended : false;
|
|
42126
|
-
// When globstar is _false_ (default), '/foo/*' is translated a regexp like
|
|
42127
|
-
// '^\/foo\/.*$' which will match any string beginning with '/foo/'
|
|
42128
|
-
// When globstar is _true_, '/foo/*' is translated to regexp like
|
|
42129
|
-
// '^\/foo\/[^/]*$' which will match any string beginning with '/foo/' BUT
|
|
42130
|
-
// which does not have a '/' to the right of it.
|
|
42131
|
-
// E.g. with '/foo/*' these will match: '/foo/bar', '/foo/bar.txt' but
|
|
42132
|
-
// these will not '/foo/bar/baz', '/foo/bar/baz.txt'
|
|
42133
|
-
// Lastely, when globstar is _true_, '/foo/**' is equivelant to '/foo/*' when
|
|
42134
|
-
// globstar is _false_
|
|
42135
|
-
var globstar = opts ? !!opts.globstar : false;
|
|
42136
|
-
// If we are doing extended matching, this boolean is true when we are inside
|
|
42137
|
-
// a group (eg {*.html,*.js}), and false otherwise.
|
|
42138
|
-
var inGroup = false;
|
|
42139
|
-
// RegExp flags (eg "i" ) to pass in to RegExp constructor.
|
|
42140
|
-
var flags = opts && typeof opts.flags === "string" ? opts.flags : "";
|
|
42141
|
-
var c;
|
|
42142
|
-
for(var i = 0, len = str.length; i < len; i++){
|
|
42143
|
-
c = str[i];
|
|
42144
|
-
switch(c){
|
|
42145
|
-
case "/":
|
|
42146
|
-
case "$":
|
|
42147
|
-
case "^":
|
|
42148
|
-
case "+":
|
|
42149
|
-
case ".":
|
|
42150
|
-
case "(":
|
|
42151
|
-
case ")":
|
|
42152
|
-
case "=":
|
|
42153
|
-
case "!":
|
|
42154
|
-
case "|":
|
|
42155
|
-
reStr += "\\" + c;
|
|
42156
|
-
break;
|
|
42157
|
-
case "?":
|
|
42158
|
-
if (extended) {
|
|
42159
|
-
reStr += ".";
|
|
42160
|
-
break;
|
|
42161
|
-
}
|
|
42162
|
-
case "[":
|
|
42163
|
-
case "]":
|
|
42164
|
-
if (extended) {
|
|
42165
|
-
reStr += c;
|
|
42166
|
-
break;
|
|
42167
|
-
}
|
|
42168
|
-
case "{":
|
|
42169
|
-
if (extended) {
|
|
42170
|
-
inGroup = true;
|
|
42171
|
-
reStr += "(";
|
|
42172
|
-
break;
|
|
42173
|
-
}
|
|
42174
|
-
case "}":
|
|
42175
|
-
if (extended) {
|
|
42176
|
-
inGroup = false;
|
|
42177
|
-
reStr += ")";
|
|
42178
|
-
break;
|
|
42179
|
-
}
|
|
42180
|
-
case ",":
|
|
42181
|
-
if (inGroup) {
|
|
42182
|
-
reStr += "|";
|
|
42183
|
-
break;
|
|
42184
|
-
}
|
|
42185
|
-
reStr += "\\" + c;
|
|
42186
|
-
break;
|
|
42187
|
-
case "*":
|
|
42188
|
-
// Move over all consecutive "*"'s.
|
|
42189
|
-
// Also store the previous and next characters
|
|
42190
|
-
var prevChar = str[i - 1];
|
|
42191
|
-
var starCount = 1;
|
|
42192
|
-
while(str[i + 1] === "*"){
|
|
42193
|
-
starCount++;
|
|
42194
|
-
i++;
|
|
42195
|
-
}
|
|
42196
|
-
var nextChar = str[i + 1];
|
|
42197
|
-
if (!globstar) {
|
|
42198
|
-
// globstar is disabled, so treat any number of "*" as one
|
|
42199
|
-
reStr += ".*";
|
|
42200
|
-
} else {
|
|
42201
|
-
// globstar is enabled, so determine if this is a globstar segment
|
|
42202
|
-
var isGlobstar = starCount > 1 // multiple "*"'s
|
|
42203
|
-
&& (prevChar === "/" || prevChar === undefined // from the start of the segment
|
|
42204
|
-
) && (nextChar === "/" || nextChar === undefined // to the end of the segment
|
|
42205
|
-
);
|
|
42206
|
-
if (isGlobstar) {
|
|
42207
|
-
// it's a globstar, so match zero or more path segments
|
|
42208
|
-
reStr += "((?:[^/]*(?:\/|$))*)";
|
|
42209
|
-
i++; // move over the "/"
|
|
42210
|
-
} else {
|
|
42211
|
-
// it's not a globstar, so only match one path segment
|
|
42212
|
-
reStr += "([^/]*)";
|
|
42213
|
-
}
|
|
42214
|
-
}
|
|
42215
|
-
break;
|
|
42216
|
-
default:
|
|
42217
|
-
reStr += c;
|
|
42218
|
-
}
|
|
42219
|
-
}
|
|
42220
|
-
// When regexp 'g' flag is specified don't
|
|
42221
|
-
// constrain the regular expression with ^ & $
|
|
42222
|
-
if (!flags || !~flags.indexOf('g')) {
|
|
42223
|
-
reStr = "^" + reStr + "$";
|
|
42224
|
-
}
|
|
42225
|
-
return new RegExp(reStr, flags);
|
|
42226
|
-
};
|
|
42227
|
-
return globToRegexp;
|
|
42228
|
-
}
|
|
42229
|
-
|
|
42230
|
-
var globToRegexpExports = requireGlobToRegexp();
|
|
42231
|
-
var GlobToRegExp = /*@__PURE__*/getDefaultExportFromCjs(globToRegexpExports);
|
|
42232
|
-
|
|
42233
|
-
/**
|
|
42234
|
-
* @file Regular expression utilities.
|
|
42235
|
-
*/ // Special RegExp constants
|
|
42236
|
-
const REGEX_START = CARET; // '^'
|
|
42237
|
-
const REGEX_END = DOLLAR_SIGN; // '$'
|
|
42238
|
-
const REGEX_ANY_CHARACTERS = DOT$1 + ASTERISK; // '.*'
|
|
42239
|
-
// Special adblock pattern symbols and their RegExp equivalents
|
|
42240
|
-
const ADBLOCK_URL_START = PIPE + PIPE; // '||'
|
|
42241
|
-
const ADBLOCK_URL_START_REGEX = '^(http|https|ws|wss)://([a-z0-9-_.]+\\.)?';
|
|
42242
|
-
const ADBLOCK_URL_SEPARATOR = CARET; // '^'
|
|
42243
|
-
const ADBLOCK_URL_SEPARATOR_REGEX = '([^ a-zA-Z0-9.%_-]|$)';
|
|
42244
|
-
const ADBLOCK_WILDCARD = ASTERISK; // '*'
|
|
42245
|
-
const ADBLOCK_WILDCARD_REGEX = REGEX_ANY_CHARACTERS;
|
|
42246
|
-
// Negation wrapper for RegExp patterns
|
|
42247
|
-
const REGEX_NEGATION_PREFIX = '^((?!';
|
|
42248
|
-
const REGEX_NEGATION_SUFFIX = ').)*$';
|
|
42249
|
-
/**
|
|
42250
|
-
* Special RegExp symbols.
|
|
42251
|
-
*
|
|
42252
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-escape
|
|
42253
|
-
*/ const SPECIAL_REGEX_SYMBOLS = new Set([
|
|
42254
|
-
ASTERISK,
|
|
42255
|
-
CARET,
|
|
42256
|
-
CLOSE_CURLY_BRACKET,
|
|
42257
|
-
CLOSE_PARENTHESIS,
|
|
42258
|
-
CLOSE_SQUARE_BRACKET,
|
|
42259
|
-
DOLLAR_SIGN,
|
|
42260
|
-
DOT$1,
|
|
42261
|
-
ESCAPE_CHARACTER,
|
|
42262
|
-
OPEN_CURLY_BRACKET,
|
|
42263
|
-
OPEN_PARENTHESIS,
|
|
42264
|
-
OPEN_SQUARE_BRACKET,
|
|
42265
|
-
PIPE,
|
|
42266
|
-
PLUS,
|
|
42267
|
-
QUESTION_MARK,
|
|
42268
|
-
SLASH
|
|
42269
|
-
]);
|
|
42270
|
-
/**
|
|
42271
|
-
* Utility functions for working with RegExp patterns.
|
|
42272
|
-
*/ class RegExpUtils {
|
|
42273
|
-
/**
|
|
42274
|
-
* Checks whether a string possibly is a RegExp pattern.
|
|
42275
|
-
* Flags are not supported.
|
|
42276
|
-
*
|
|
42277
|
-
* Note: it does not perform a full validation of the pattern,
|
|
42278
|
-
* it just checks if the string starts and ends with a slash.
|
|
42279
|
-
*
|
|
42280
|
-
* @param pattern Pattern to check.
|
|
42281
|
-
*
|
|
42282
|
-
* @returns `true` if the string is a RegExp pattern, `false` otherwise.
|
|
42283
|
-
*/ static isRegexPattern(pattern) {
|
|
42284
|
-
const trimmedPattern = pattern.trim();
|
|
42285
|
-
// Avoid false positives
|
|
42286
|
-
return trimmedPattern.length > REGEX_MARKER.length * 2 && trimmedPattern.startsWith(REGEX_MARKER) && trimmedPattern.endsWith(REGEX_MARKER) && trimmedPattern[REGEX_MARKER.length - 2] !== ESCAPE_CHARACTER;
|
|
42287
|
-
}
|
|
42288
|
-
/**
|
|
42289
|
-
* Checks whether a string is a negated RegExp pattern.
|
|
42290
|
-
*
|
|
42291
|
-
* @param pattern Pattern to check.
|
|
42292
|
-
*
|
|
42293
|
-
* @returns `true` if the string is a negated RegExp pattern, `false` otherwise.
|
|
42294
|
-
*/ static isNegatedRegexPattern(pattern) {
|
|
42295
|
-
if (pattern.startsWith(REGEX_MARKER) && pattern.endsWith(REGEX_MARKER)) {
|
|
42296
|
-
const innerPattern = pattern.slice(REGEX_MARKER.length, pattern.length - REGEX_MARKER.length);
|
|
42297
|
-
return innerPattern.startsWith(REGEX_NEGATION_PREFIX) && innerPattern.endsWith(REGEX_NEGATION_SUFFIX);
|
|
42298
|
-
}
|
|
42299
|
-
return pattern.startsWith(REGEX_NEGATION_PREFIX) && pattern.endsWith(REGEX_NEGATION_SUFFIX);
|
|
42300
|
-
}
|
|
42301
|
-
/**
|
|
42302
|
-
* Removes negation from a RegExp pattern.
|
|
42303
|
-
*
|
|
42304
|
-
* @param pattern RegExp pattern to remove negation from.
|
|
42305
|
-
*
|
|
42306
|
-
* @returns RegExp pattern without negation.
|
|
42307
|
-
*/ static removeNegationFromRegexPattern(pattern) {
|
|
42308
|
-
let result = pattern.trim();
|
|
42309
|
-
const slashes = RegExpUtils.isRegexPattern(result);
|
|
42310
|
-
if (slashes) {
|
|
42311
|
-
result = result.substring(REGEX_MARKER.length, result.length - REGEX_MARKER.length);
|
|
42312
|
-
}
|
|
42313
|
-
if (result.startsWith(REGEX_NEGATION_PREFIX) && result.endsWith(REGEX_NEGATION_SUFFIX)) {
|
|
42314
|
-
result = result.substring(REGEX_NEGATION_PREFIX.length, result.length - REGEX_NEGATION_SUFFIX.length);
|
|
42315
|
-
}
|
|
42316
|
-
return slashes ? `${REGEX_MARKER}${result}${REGEX_MARKER}` : result;
|
|
42317
|
-
}
|
|
42318
|
-
/**
|
|
42319
|
-
* Negates a RegExp pattern. Technically, this method wraps the pattern in `^((?!` and `).)*$`.
|
|
42320
|
-
*
|
|
42321
|
-
* RegExp modifiers are not supported.
|
|
42322
|
-
*
|
|
42323
|
-
* @param pattern Pattern to negate (can be wrapped in slashes or not).
|
|
42324
|
-
*
|
|
42325
|
-
* @returns Negated RegExp pattern.
|
|
42326
|
-
*/ static negateRegexPattern(pattern) {
|
|
42327
|
-
let result = pattern.trim();
|
|
42328
|
-
let slashes = false;
|
|
42329
|
-
// Remove the leading and trailing slashes (/)
|
|
42330
|
-
if (RegExpUtils.isRegexPattern(result)) {
|
|
42331
|
-
result = result.substring(REGEX_MARKER.length, result.length - REGEX_MARKER.length);
|
|
42332
|
-
slashes = true;
|
|
42333
|
-
}
|
|
42334
|
-
// Only negate the pattern if it's not already negated
|
|
42335
|
-
if (!(result.startsWith(REGEX_NEGATION_PREFIX) && result.endsWith(REGEX_NEGATION_SUFFIX))) {
|
|
42336
|
-
// Remove leading caret (^)
|
|
42337
|
-
if (result.startsWith(REGEX_START)) {
|
|
42338
|
-
result = result.substring(REGEX_START.length);
|
|
42339
|
-
}
|
|
42340
|
-
// Remove trailing dollar sign ($)
|
|
42341
|
-
if (result.endsWith(REGEX_END)) {
|
|
42342
|
-
result = result.substring(0, result.length - REGEX_END.length);
|
|
42343
|
-
}
|
|
42344
|
-
// Wrap the pattern in the negation
|
|
42345
|
-
result = `${REGEX_NEGATION_PREFIX}${result}${REGEX_NEGATION_SUFFIX}`;
|
|
42346
|
-
}
|
|
42347
|
-
// Add the leading and trailing slashes back if they were there
|
|
42348
|
-
if (slashes) {
|
|
42349
|
-
result = `${REGEX_MARKER}${result}${REGEX_MARKER}`;
|
|
42350
|
-
}
|
|
42351
|
-
return result;
|
|
42352
|
-
}
|
|
42353
|
-
/**
|
|
42354
|
-
* Ensures that a pattern is wrapped in slashes.
|
|
42355
|
-
*
|
|
42356
|
-
* @param pattern Pattern to ensure slashes for.
|
|
42357
|
-
*
|
|
42358
|
-
* @returns Pattern with slashes.
|
|
42359
|
-
*/ static ensureSlashes(pattern) {
|
|
42360
|
-
let result = pattern;
|
|
42361
|
-
if (!result.startsWith(REGEX_MARKER)) {
|
|
42362
|
-
result = `${REGEX_MARKER}${result}`;
|
|
42363
|
-
}
|
|
42364
|
-
if (!result.endsWith(REGEX_MARKER)) {
|
|
42365
|
-
result += REGEX_MARKER;
|
|
42366
|
-
}
|
|
42367
|
-
return result;
|
|
42368
|
-
}
|
|
42369
|
-
/**
|
|
42370
|
-
* Converts a basic adblock rule pattern to a RegExp pattern. Based on
|
|
42371
|
-
* https://github.com/AdguardTeam/tsurlfilter/blob/9b26e0b4a0e30b87690bc60f7cf377d112c3085c/packages/tsurlfilter/src/rules/simple-regex.ts#L219.
|
|
42372
|
-
*
|
|
42373
|
-
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#basic-rules}
|
|
42374
|
-
*
|
|
42375
|
-
* @param pattern Pattern to convert.
|
|
42376
|
-
*
|
|
42377
|
-
* @returns RegExp equivalent of the pattern.
|
|
42378
|
-
*/ static patternToRegexp(pattern) {
|
|
42379
|
-
const trimmed = pattern.trim();
|
|
42380
|
-
// Return regex for any character sequence if the pattern is just |, ||, * or empty
|
|
42381
|
-
if (trimmed === ADBLOCK_URL_START || trimmed === PIPE || trimmed === ADBLOCK_WILDCARD || trimmed === EMPTY) {
|
|
42382
|
-
return REGEX_ANY_CHARACTERS;
|
|
42383
|
-
}
|
|
42384
|
-
// If the pattern is already a RegExp, just return it, but remove the leading and trailing slashes
|
|
42385
|
-
if (RegExpUtils.isRegexPattern(pattern)) {
|
|
42386
|
-
return pattern.substring(REGEX_MARKER.length, pattern.length - REGEX_MARKER.length);
|
|
42387
|
-
}
|
|
42388
|
-
let result = EMPTY;
|
|
42389
|
-
let offset = 0;
|
|
42390
|
-
let len = trimmed.length;
|
|
42391
|
-
// Handle leading pipes
|
|
42392
|
-
if (trimmed[0] === PIPE) {
|
|
42393
|
-
if (trimmed[1] === PIPE) {
|
|
42394
|
-
// Replace adblock url start (||) with its RegExp equivalent
|
|
42395
|
-
result += ADBLOCK_URL_START_REGEX;
|
|
42396
|
-
offset = ADBLOCK_URL_START.length;
|
|
42397
|
-
} else {
|
|
42398
|
-
// Replace single pipe (|) with the RegExp start symbol (^)
|
|
42399
|
-
result += REGEX_START;
|
|
42400
|
-
offset = REGEX_START.length;
|
|
42401
|
-
}
|
|
42402
|
-
}
|
|
42403
|
-
// Handle trailing pipes
|
|
42404
|
-
let trailingPipe = false;
|
|
42405
|
-
if (trimmed.endsWith(PIPE)) {
|
|
42406
|
-
trailingPipe = true;
|
|
42407
|
-
len -= PIPE.length;
|
|
42408
|
-
}
|
|
42409
|
-
// Handle the rest of the pattern, if any
|
|
42410
|
-
for(; offset < len; offset += 1){
|
|
42411
|
-
if (trimmed[offset] === ADBLOCK_WILDCARD) {
|
|
42412
|
-
// Replace adblock wildcard (*) with its RegExp equivalent
|
|
42413
|
-
result += ADBLOCK_WILDCARD_REGEX;
|
|
42414
|
-
} else if (trimmed[offset] === ADBLOCK_URL_SEPARATOR) {
|
|
42415
|
-
// Replace adblock url separator (^) with its RegExp equivalent
|
|
42416
|
-
result += ADBLOCK_URL_SEPARATOR_REGEX;
|
|
42417
|
-
} else if (SPECIAL_REGEX_SYMBOLS.has(trimmed[offset])) {
|
|
42418
|
-
// Escape special RegExp symbols (we handled pipe (|) and asterisk (*) already)
|
|
42419
|
-
result += ESCAPE_CHARACTER + trimmed[offset];
|
|
42420
|
-
} else {
|
|
42421
|
-
// Just add any other character
|
|
42422
|
-
result += trimmed[offset];
|
|
42423
|
-
}
|
|
42424
|
-
}
|
|
42425
|
-
// Handle trailing pipes
|
|
42426
|
-
if (trailingPipe) {
|
|
42427
|
-
// Replace trailing pipe (|) with the RegExp end symbol ($)
|
|
42428
|
-
result += REGEX_END;
|
|
42429
|
-
}
|
|
42430
|
-
return result;
|
|
42431
|
-
}
|
|
42432
|
-
/**
|
|
42433
|
-
* Creates a length-matching regular expression string: /^(?=.{min,max}$).*\/s
|
|
42434
|
-
* Where:
|
|
42435
|
-
* - (?=.{min,max}$) is a lookahead that ensures the string length is between min and max
|
|
42436
|
-
* - .* matches any character (including newlines, due to the 's' flag).
|
|
42437
|
-
*
|
|
42438
|
-
* @param min Minimum length or `null` for no minimum (default to `0`).
|
|
42439
|
-
* @param max Maximum length or `null` for no maximum (default to no maximum).
|
|
42440
|
-
*
|
|
42441
|
-
* @returns Length-matching regular expression string.
|
|
42442
|
-
*/ static getLengthRegexp(min, max) {
|
|
42443
|
-
return `/^(?=.{${min ?? 0},${max ?? ''}}$).*/s`;
|
|
42444
|
-
}
|
|
42445
|
-
/**
|
|
42446
|
-
* Converts a glob pattern to a RegExp string with slashes and 's' flag.
|
|
42447
|
-
*
|
|
42448
|
-
* @param glob Glob pattern to convert.
|
|
42449
|
-
*
|
|
42450
|
-
* @returns RegExp string.
|
|
42451
|
-
*
|
|
42452
|
-
* @example
|
|
42453
|
-
* // Returns '/^foo.*bar$/s'
|
|
42454
|
-
* RegExpUtils.globToRegExp('foo*bar');
|
|
42455
|
-
*/ static globToRegExp(glob) {
|
|
42456
|
-
return `${REGEX_MARKER + GlobToRegExp(glob).source + REGEX_MARKER}s`;
|
|
42457
|
-
}
|
|
42458
|
-
}
|
|
42459
|
-
|
|
42460
42109
|
var kindOf;
|
|
42461
42110
|
var hasRequiredKindOf;
|
|
42462
42111
|
|
|
@@ -42865,7 +42514,7 @@ var cloneDeep = /*@__PURE__*/getDefaultExportFromCjs(cloneDeepExports);
|
|
|
42865
42514
|
}
|
|
42866
42515
|
|
|
42867
42516
|
/*
|
|
42868
|
-
* AGTree v4.2.1 (build date:
|
|
42517
|
+
* AGTree v4.2.1 (build date: Tue, 25 Aug 2026 03:14:57 GMT)
|
|
42869
42518
|
* (c) 2026 Adguard Software Ltd.
|
|
42870
42519
|
* Released under the MIT license
|
|
42871
42520
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -43330,6 +42979,357 @@ const PSEUDO_ELEMENT_NAMES = new Set([
|
|
|
43330
42979
|
return result;
|
|
43331
42980
|
}
|
|
43332
42981
|
|
|
42982
|
+
var globToRegexp;
|
|
42983
|
+
var hasRequiredGlobToRegexp;
|
|
42984
|
+
|
|
42985
|
+
function requireGlobToRegexp () {
|
|
42986
|
+
if (hasRequiredGlobToRegexp) return globToRegexp;
|
|
42987
|
+
hasRequiredGlobToRegexp = 1;
|
|
42988
|
+
globToRegexp = function(glob, opts) {
|
|
42989
|
+
if (typeof glob !== 'string') {
|
|
42990
|
+
throw new TypeError('Expected a string');
|
|
42991
|
+
}
|
|
42992
|
+
var str = String(glob);
|
|
42993
|
+
// The regexp we are building, as a string.
|
|
42994
|
+
var reStr = "";
|
|
42995
|
+
// Whether we are matching so called "extended" globs (like bash) and should
|
|
42996
|
+
// support single character matching, matching ranges of characters, group
|
|
42997
|
+
// matching, etc.
|
|
42998
|
+
var extended = opts ? !!opts.extended : false;
|
|
42999
|
+
// When globstar is _false_ (default), '/foo/*' is translated a regexp like
|
|
43000
|
+
// '^\/foo\/.*$' which will match any string beginning with '/foo/'
|
|
43001
|
+
// When globstar is _true_, '/foo/*' is translated to regexp like
|
|
43002
|
+
// '^\/foo\/[^/]*$' which will match any string beginning with '/foo/' BUT
|
|
43003
|
+
// which does not have a '/' to the right of it.
|
|
43004
|
+
// E.g. with '/foo/*' these will match: '/foo/bar', '/foo/bar.txt' but
|
|
43005
|
+
// these will not '/foo/bar/baz', '/foo/bar/baz.txt'
|
|
43006
|
+
// Lastely, when globstar is _true_, '/foo/**' is equivelant to '/foo/*' when
|
|
43007
|
+
// globstar is _false_
|
|
43008
|
+
var globstar = opts ? !!opts.globstar : false;
|
|
43009
|
+
// If we are doing extended matching, this boolean is true when we are inside
|
|
43010
|
+
// a group (eg {*.html,*.js}), and false otherwise.
|
|
43011
|
+
var inGroup = false;
|
|
43012
|
+
// RegExp flags (eg "i" ) to pass in to RegExp constructor.
|
|
43013
|
+
var flags = opts && typeof opts.flags === "string" ? opts.flags : "";
|
|
43014
|
+
var c;
|
|
43015
|
+
for(var i = 0, len = str.length; i < len; i++){
|
|
43016
|
+
c = str[i];
|
|
43017
|
+
switch(c){
|
|
43018
|
+
case "/":
|
|
43019
|
+
case "$":
|
|
43020
|
+
case "^":
|
|
43021
|
+
case "+":
|
|
43022
|
+
case ".":
|
|
43023
|
+
case "(":
|
|
43024
|
+
case ")":
|
|
43025
|
+
case "=":
|
|
43026
|
+
case "!":
|
|
43027
|
+
case "|":
|
|
43028
|
+
reStr += "\\" + c;
|
|
43029
|
+
break;
|
|
43030
|
+
case "?":
|
|
43031
|
+
if (extended) {
|
|
43032
|
+
reStr += ".";
|
|
43033
|
+
break;
|
|
43034
|
+
}
|
|
43035
|
+
case "[":
|
|
43036
|
+
case "]":
|
|
43037
|
+
if (extended) {
|
|
43038
|
+
reStr += c;
|
|
43039
|
+
break;
|
|
43040
|
+
}
|
|
43041
|
+
case "{":
|
|
43042
|
+
if (extended) {
|
|
43043
|
+
inGroup = true;
|
|
43044
|
+
reStr += "(";
|
|
43045
|
+
break;
|
|
43046
|
+
}
|
|
43047
|
+
case "}":
|
|
43048
|
+
if (extended) {
|
|
43049
|
+
inGroup = false;
|
|
43050
|
+
reStr += ")";
|
|
43051
|
+
break;
|
|
43052
|
+
}
|
|
43053
|
+
case ",":
|
|
43054
|
+
if (inGroup) {
|
|
43055
|
+
reStr += "|";
|
|
43056
|
+
break;
|
|
43057
|
+
}
|
|
43058
|
+
reStr += "\\" + c;
|
|
43059
|
+
break;
|
|
43060
|
+
case "*":
|
|
43061
|
+
// Move over all consecutive "*"'s.
|
|
43062
|
+
// Also store the previous and next characters
|
|
43063
|
+
var prevChar = str[i - 1];
|
|
43064
|
+
var starCount = 1;
|
|
43065
|
+
while(str[i + 1] === "*"){
|
|
43066
|
+
starCount++;
|
|
43067
|
+
i++;
|
|
43068
|
+
}
|
|
43069
|
+
var nextChar = str[i + 1];
|
|
43070
|
+
if (!globstar) {
|
|
43071
|
+
// globstar is disabled, so treat any number of "*" as one
|
|
43072
|
+
reStr += ".*";
|
|
43073
|
+
} else {
|
|
43074
|
+
// globstar is enabled, so determine if this is a globstar segment
|
|
43075
|
+
var isGlobstar = starCount > 1 // multiple "*"'s
|
|
43076
|
+
&& (prevChar === "/" || prevChar === undefined // from the start of the segment
|
|
43077
|
+
) && (nextChar === "/" || nextChar === undefined // to the end of the segment
|
|
43078
|
+
);
|
|
43079
|
+
if (isGlobstar) {
|
|
43080
|
+
// it's a globstar, so match zero or more path segments
|
|
43081
|
+
reStr += "((?:[^/]*(?:\/|$))*)";
|
|
43082
|
+
i++; // move over the "/"
|
|
43083
|
+
} else {
|
|
43084
|
+
// it's not a globstar, so only match one path segment
|
|
43085
|
+
reStr += "([^/]*)";
|
|
43086
|
+
}
|
|
43087
|
+
}
|
|
43088
|
+
break;
|
|
43089
|
+
default:
|
|
43090
|
+
reStr += c;
|
|
43091
|
+
}
|
|
43092
|
+
}
|
|
43093
|
+
// When regexp 'g' flag is specified don't
|
|
43094
|
+
// constrain the regular expression with ^ & $
|
|
43095
|
+
if (!flags || !~flags.indexOf('g')) {
|
|
43096
|
+
reStr = "^" + reStr + "$";
|
|
43097
|
+
}
|
|
43098
|
+
return new RegExp(reStr, flags);
|
|
43099
|
+
};
|
|
43100
|
+
return globToRegexp;
|
|
43101
|
+
}
|
|
43102
|
+
|
|
43103
|
+
var globToRegexpExports = requireGlobToRegexp();
|
|
43104
|
+
var GlobToRegExp = /*@__PURE__*/getDefaultExportFromCjs(globToRegexpExports);
|
|
43105
|
+
|
|
43106
|
+
/**
|
|
43107
|
+
* @file Regular expression utilities.
|
|
43108
|
+
*/ // Special RegExp constants
|
|
43109
|
+
const REGEX_START = CARET; // '^'
|
|
43110
|
+
const REGEX_END = DOLLAR_SIGN; // '$'
|
|
43111
|
+
const REGEX_ANY_CHARACTERS = DOT$1 + ASTERISK; // '.*'
|
|
43112
|
+
// Special adblock pattern symbols and their RegExp equivalents
|
|
43113
|
+
const ADBLOCK_URL_START = PIPE + PIPE; // '||'
|
|
43114
|
+
const ADBLOCK_URL_START_REGEX = '^(http|https|ws|wss)://([a-z0-9-_.]+\\.)?';
|
|
43115
|
+
const ADBLOCK_URL_SEPARATOR = CARET; // '^'
|
|
43116
|
+
const ADBLOCK_URL_SEPARATOR_REGEX = '([^ a-zA-Z0-9.%_-]|$)';
|
|
43117
|
+
const ADBLOCK_WILDCARD = ASTERISK; // '*'
|
|
43118
|
+
const ADBLOCK_WILDCARD_REGEX = REGEX_ANY_CHARACTERS;
|
|
43119
|
+
// Negation wrapper for RegExp patterns
|
|
43120
|
+
const REGEX_NEGATION_PREFIX = '^((?!';
|
|
43121
|
+
const REGEX_NEGATION_SUFFIX = ').)*$';
|
|
43122
|
+
/**
|
|
43123
|
+
* Special RegExp symbols.
|
|
43124
|
+
*
|
|
43125
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-escape
|
|
43126
|
+
*/ const SPECIAL_REGEX_SYMBOLS = new Set([
|
|
43127
|
+
ASTERISK,
|
|
43128
|
+
CARET,
|
|
43129
|
+
CLOSE_CURLY_BRACKET,
|
|
43130
|
+
CLOSE_PARENTHESIS,
|
|
43131
|
+
CLOSE_SQUARE_BRACKET,
|
|
43132
|
+
DOLLAR_SIGN,
|
|
43133
|
+
DOT$1,
|
|
43134
|
+
ESCAPE_CHARACTER,
|
|
43135
|
+
OPEN_CURLY_BRACKET,
|
|
43136
|
+
OPEN_PARENTHESIS,
|
|
43137
|
+
OPEN_SQUARE_BRACKET,
|
|
43138
|
+
PIPE,
|
|
43139
|
+
PLUS,
|
|
43140
|
+
QUESTION_MARK,
|
|
43141
|
+
SLASH
|
|
43142
|
+
]);
|
|
43143
|
+
/**
|
|
43144
|
+
* Utility functions for working with RegExp patterns.
|
|
43145
|
+
*/ class RegExpUtils {
|
|
43146
|
+
/**
|
|
43147
|
+
* Checks whether a string possibly is a RegExp pattern.
|
|
43148
|
+
* Flags are not supported.
|
|
43149
|
+
*
|
|
43150
|
+
* Note: it does not perform a full validation of the pattern,
|
|
43151
|
+
* it just checks if the string starts and ends with a slash.
|
|
43152
|
+
*
|
|
43153
|
+
* @param pattern Pattern to check.
|
|
43154
|
+
*
|
|
43155
|
+
* @returns `true` if the string is a RegExp pattern, `false` otherwise.
|
|
43156
|
+
*/ static isRegexPattern(pattern) {
|
|
43157
|
+
const trimmedPattern = pattern.trim();
|
|
43158
|
+
// Avoid false positives
|
|
43159
|
+
return trimmedPattern.length > REGEX_MARKER.length * 2 && trimmedPattern.startsWith(REGEX_MARKER) && trimmedPattern.endsWith(REGEX_MARKER) && trimmedPattern[REGEX_MARKER.length - 2] !== ESCAPE_CHARACTER;
|
|
43160
|
+
}
|
|
43161
|
+
/**
|
|
43162
|
+
* Checks whether a string is a negated RegExp pattern.
|
|
43163
|
+
*
|
|
43164
|
+
* @param pattern Pattern to check.
|
|
43165
|
+
*
|
|
43166
|
+
* @returns `true` if the string is a negated RegExp pattern, `false` otherwise.
|
|
43167
|
+
*/ static isNegatedRegexPattern(pattern) {
|
|
43168
|
+
if (pattern.startsWith(REGEX_MARKER) && pattern.endsWith(REGEX_MARKER)) {
|
|
43169
|
+
const innerPattern = pattern.slice(REGEX_MARKER.length, pattern.length - REGEX_MARKER.length);
|
|
43170
|
+
return innerPattern.startsWith(REGEX_NEGATION_PREFIX) && innerPattern.endsWith(REGEX_NEGATION_SUFFIX);
|
|
43171
|
+
}
|
|
43172
|
+
return pattern.startsWith(REGEX_NEGATION_PREFIX) && pattern.endsWith(REGEX_NEGATION_SUFFIX);
|
|
43173
|
+
}
|
|
43174
|
+
/**
|
|
43175
|
+
* Removes negation from a RegExp pattern.
|
|
43176
|
+
*
|
|
43177
|
+
* @param pattern RegExp pattern to remove negation from.
|
|
43178
|
+
*
|
|
43179
|
+
* @returns RegExp pattern without negation.
|
|
43180
|
+
*/ static removeNegationFromRegexPattern(pattern) {
|
|
43181
|
+
let result = pattern.trim();
|
|
43182
|
+
const slashes = RegExpUtils.isRegexPattern(result);
|
|
43183
|
+
if (slashes) {
|
|
43184
|
+
result = result.substring(REGEX_MARKER.length, result.length - REGEX_MARKER.length);
|
|
43185
|
+
}
|
|
43186
|
+
if (result.startsWith(REGEX_NEGATION_PREFIX) && result.endsWith(REGEX_NEGATION_SUFFIX)) {
|
|
43187
|
+
result = result.substring(REGEX_NEGATION_PREFIX.length, result.length - REGEX_NEGATION_SUFFIX.length);
|
|
43188
|
+
}
|
|
43189
|
+
return slashes ? `${REGEX_MARKER}${result}${REGEX_MARKER}` : result;
|
|
43190
|
+
}
|
|
43191
|
+
/**
|
|
43192
|
+
* Negates a RegExp pattern. Technically, this method wraps the pattern in `^((?!` and `).)*$`.
|
|
43193
|
+
*
|
|
43194
|
+
* RegExp modifiers are not supported.
|
|
43195
|
+
*
|
|
43196
|
+
* @param pattern Pattern to negate (can be wrapped in slashes or not).
|
|
43197
|
+
*
|
|
43198
|
+
* @returns Negated RegExp pattern.
|
|
43199
|
+
*/ static negateRegexPattern(pattern) {
|
|
43200
|
+
let result = pattern.trim();
|
|
43201
|
+
let slashes = false;
|
|
43202
|
+
// Remove the leading and trailing slashes (/)
|
|
43203
|
+
if (RegExpUtils.isRegexPattern(result)) {
|
|
43204
|
+
result = result.substring(REGEX_MARKER.length, result.length - REGEX_MARKER.length);
|
|
43205
|
+
slashes = true;
|
|
43206
|
+
}
|
|
43207
|
+
// Only negate the pattern if it's not already negated
|
|
43208
|
+
if (!(result.startsWith(REGEX_NEGATION_PREFIX) && result.endsWith(REGEX_NEGATION_SUFFIX))) {
|
|
43209
|
+
// Remove leading caret (^)
|
|
43210
|
+
if (result.startsWith(REGEX_START)) {
|
|
43211
|
+
result = result.substring(REGEX_START.length);
|
|
43212
|
+
}
|
|
43213
|
+
// Remove trailing dollar sign ($)
|
|
43214
|
+
if (result.endsWith(REGEX_END)) {
|
|
43215
|
+
result = result.substring(0, result.length - REGEX_END.length);
|
|
43216
|
+
}
|
|
43217
|
+
// Wrap the pattern in the negation
|
|
43218
|
+
result = `${REGEX_NEGATION_PREFIX}${result}${REGEX_NEGATION_SUFFIX}`;
|
|
43219
|
+
}
|
|
43220
|
+
// Add the leading and trailing slashes back if they were there
|
|
43221
|
+
if (slashes) {
|
|
43222
|
+
result = `${REGEX_MARKER}${result}${REGEX_MARKER}`;
|
|
43223
|
+
}
|
|
43224
|
+
return result;
|
|
43225
|
+
}
|
|
43226
|
+
/**
|
|
43227
|
+
* Ensures that a pattern is wrapped in slashes.
|
|
43228
|
+
*
|
|
43229
|
+
* @param pattern Pattern to ensure slashes for.
|
|
43230
|
+
*
|
|
43231
|
+
* @returns Pattern with slashes.
|
|
43232
|
+
*/ static ensureSlashes(pattern) {
|
|
43233
|
+
let result = pattern;
|
|
43234
|
+
if (!result.startsWith(REGEX_MARKER)) {
|
|
43235
|
+
result = `${REGEX_MARKER}${result}`;
|
|
43236
|
+
}
|
|
43237
|
+
if (!result.endsWith(REGEX_MARKER)) {
|
|
43238
|
+
result += REGEX_MARKER;
|
|
43239
|
+
}
|
|
43240
|
+
return result;
|
|
43241
|
+
}
|
|
43242
|
+
/**
|
|
43243
|
+
* Converts a basic adblock rule pattern to a RegExp pattern. Based on
|
|
43244
|
+
* https://github.com/AdguardTeam/tsurlfilter/blob/9b26e0b4a0e30b87690bc60f7cf377d112c3085c/packages/tsurlfilter/src/rules/simple-regex.ts#L219.
|
|
43245
|
+
*
|
|
43246
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#basic-rules}
|
|
43247
|
+
*
|
|
43248
|
+
* @param pattern Pattern to convert.
|
|
43249
|
+
*
|
|
43250
|
+
* @returns RegExp equivalent of the pattern.
|
|
43251
|
+
*/ static patternToRegexp(pattern) {
|
|
43252
|
+
const trimmed = pattern.trim();
|
|
43253
|
+
// Return regex for any character sequence if the pattern is just |, ||, * or empty
|
|
43254
|
+
if (trimmed === ADBLOCK_URL_START || trimmed === PIPE || trimmed === ADBLOCK_WILDCARD || trimmed === EMPTY) {
|
|
43255
|
+
return REGEX_ANY_CHARACTERS;
|
|
43256
|
+
}
|
|
43257
|
+
// If the pattern is already a RegExp, just return it, but remove the leading and trailing slashes
|
|
43258
|
+
if (RegExpUtils.isRegexPattern(pattern)) {
|
|
43259
|
+
return pattern.substring(REGEX_MARKER.length, pattern.length - REGEX_MARKER.length);
|
|
43260
|
+
}
|
|
43261
|
+
let result = EMPTY;
|
|
43262
|
+
let offset = 0;
|
|
43263
|
+
let len = trimmed.length;
|
|
43264
|
+
// Handle leading pipes
|
|
43265
|
+
if (trimmed[0] === PIPE) {
|
|
43266
|
+
if (trimmed[1] === PIPE) {
|
|
43267
|
+
// Replace adblock url start (||) with its RegExp equivalent
|
|
43268
|
+
result += ADBLOCK_URL_START_REGEX;
|
|
43269
|
+
offset = ADBLOCK_URL_START.length;
|
|
43270
|
+
} else {
|
|
43271
|
+
// Replace single pipe (|) with the RegExp start symbol (^)
|
|
43272
|
+
result += REGEX_START;
|
|
43273
|
+
offset = REGEX_START.length;
|
|
43274
|
+
}
|
|
43275
|
+
}
|
|
43276
|
+
// Handle trailing pipes
|
|
43277
|
+
let trailingPipe = false;
|
|
43278
|
+
if (trimmed.endsWith(PIPE)) {
|
|
43279
|
+
trailingPipe = true;
|
|
43280
|
+
len -= PIPE.length;
|
|
43281
|
+
}
|
|
43282
|
+
// Handle the rest of the pattern, if any
|
|
43283
|
+
for(; offset < len; offset += 1){
|
|
43284
|
+
if (trimmed[offset] === ADBLOCK_WILDCARD) {
|
|
43285
|
+
// Replace adblock wildcard (*) with its RegExp equivalent
|
|
43286
|
+
result += ADBLOCK_WILDCARD_REGEX;
|
|
43287
|
+
} else if (trimmed[offset] === ADBLOCK_URL_SEPARATOR) {
|
|
43288
|
+
// Replace adblock url separator (^) with its RegExp equivalent
|
|
43289
|
+
result += ADBLOCK_URL_SEPARATOR_REGEX;
|
|
43290
|
+
} else if (SPECIAL_REGEX_SYMBOLS.has(trimmed[offset])) {
|
|
43291
|
+
// Escape special RegExp symbols (we handled pipe (|) and asterisk (*) already)
|
|
43292
|
+
result += ESCAPE_CHARACTER + trimmed[offset];
|
|
43293
|
+
} else {
|
|
43294
|
+
// Just add any other character
|
|
43295
|
+
result += trimmed[offset];
|
|
43296
|
+
}
|
|
43297
|
+
}
|
|
43298
|
+
// Handle trailing pipes
|
|
43299
|
+
if (trailingPipe) {
|
|
43300
|
+
// Replace trailing pipe (|) with the RegExp end symbol ($)
|
|
43301
|
+
result += REGEX_END;
|
|
43302
|
+
}
|
|
43303
|
+
return result;
|
|
43304
|
+
}
|
|
43305
|
+
/**
|
|
43306
|
+
* Creates a length-matching regular expression string: /^(?=.{min,max}$).*\/s
|
|
43307
|
+
* Where:
|
|
43308
|
+
* - (?=.{min,max}$) is a lookahead that ensures the string length is between min and max
|
|
43309
|
+
* - .* matches any character (including newlines, due to the 's' flag).
|
|
43310
|
+
*
|
|
43311
|
+
* @param min Minimum length or `null` for no minimum (default to `0`).
|
|
43312
|
+
* @param max Maximum length or `null` for no maximum (default to no maximum).
|
|
43313
|
+
*
|
|
43314
|
+
* @returns Length-matching regular expression string.
|
|
43315
|
+
*/ static getLengthRegexp(min, max) {
|
|
43316
|
+
return `/^(?=.{${min ?? 0},${max ?? ''}}$).*/s`;
|
|
43317
|
+
}
|
|
43318
|
+
/**
|
|
43319
|
+
* Converts a glob pattern to a RegExp string with slashes and 's' flag.
|
|
43320
|
+
*
|
|
43321
|
+
* @param glob Glob pattern to convert.
|
|
43322
|
+
*
|
|
43323
|
+
* @returns RegExp string.
|
|
43324
|
+
*
|
|
43325
|
+
* @example
|
|
43326
|
+
* // Returns '/^foo.*bar$/s'
|
|
43327
|
+
* RegExpUtils.globToRegExp('foo*bar');
|
|
43328
|
+
*/ static globToRegExp(glob) {
|
|
43329
|
+
return `${REGEX_MARKER + GlobToRegExp(glob).source + REGEX_MARKER}s`;
|
|
43330
|
+
}
|
|
43331
|
+
}
|
|
43332
|
+
|
|
43333
43333
|
/**
|
|
43334
43334
|
* @file Converter for request header removal rules.
|
|
43335
43335
|
*/ const ADG_REMOVEHEADER_MODIFIER = 'removeheader';
|
package/dist/package.json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adguard/dnr-converter",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A converter that transforms adblock-style filtering rules into rules compatible with the Declarative Net Request (DNR) API.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -57,12 +57,12 @@
|
|
|
57
57
|
"@adguard/re2-wasm": "1.2.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@adguard/scriptlets": "2.5.
|
|
60
|
+
"@adguard/scriptlets": "2.5.1",
|
|
61
61
|
"commander": "^12.1.0",
|
|
62
62
|
"punycode": "2.3.1",
|
|
63
63
|
"valibot": "^1.1.0",
|
|
64
|
-
"@adguard/
|
|
65
|
-
"@adguard/
|
|
64
|
+
"@adguard/logger": "^2.0.0",
|
|
65
|
+
"@adguard/agtree": "^4.2.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@rollup/plugin-commonjs": "^28.0.1",
|
|
@@ -96,8 +96,8 @@
|
|
|
96
96
|
"tsx": "^4.19.3",
|
|
97
97
|
"typescript": "^5.7.3",
|
|
98
98
|
"vitest": "^4.1.5",
|
|
99
|
-
"@adguard/
|
|
100
|
-
"@adguard/
|
|
99
|
+
"@adguard/eslint-plugin-logger-context": "^1.0.1",
|
|
100
|
+
"@adguard/tsurlfilter": "^6.0.3"
|
|
101
101
|
},
|
|
102
102
|
"scripts": {
|
|
103
103
|
"lint": "pnpm lint:code && pnpm lint:types && pnpm lint:md",
|