@adguard/agtree 2.1.4 → 2.2.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/dist/agtree.d.ts +2 -1
- package/dist/agtree.js +36 -9
- package/dist/agtree.mjs +36 -9
- package/dist/compatibility-table-data.js +296 -148
- package/package.json +3 -3
package/dist/agtree.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v2.
|
|
2
|
+
* AGTree v2.2.0 (build date: Wed, 27 Nov 2024 16:28:27 GMT)
|
|
3
3
|
* (c) 2024 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -3699,6 +3699,7 @@ declare const modifierDataSchema: zod.ZodEffects<zod.ZodTypeAny, {
|
|
|
3699
3699
|
exceptionOnly: boolean;
|
|
3700
3700
|
valueOptional: boolean;
|
|
3701
3701
|
valueFormat: string | null;
|
|
3702
|
+
valueFormatFlags: string | null;
|
|
3702
3703
|
}, any>;
|
|
3703
3704
|
/**
|
|
3704
3705
|
* Type of the modifier data schema.
|
package/dist/agtree.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v2.
|
|
2
|
+
* AGTree v2.2.0 (build date: Wed, 27 Nov 2024 16:28:27 GMT)
|
|
3
3
|
* (c) 2024 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -13,7 +13,6 @@ var sprintfJs = require('sprintf-js');
|
|
|
13
13
|
var cssTokenizer = require('@adguard/css-tokenizer');
|
|
14
14
|
var tldts = require('tldts');
|
|
15
15
|
var isIp = require('is-ip');
|
|
16
|
-
var XRegExp = require('xregexp');
|
|
17
16
|
var cloneDeep = require('clone-deep');
|
|
18
17
|
var compatibilityTableData_js = require('./compatibility-table-data.js');
|
|
19
18
|
var zod = require('zod');
|
|
@@ -10764,10 +10763,11 @@ const isCustomValueFormatValidator = (valueFormat) => {
|
|
|
10764
10763
|
*
|
|
10765
10764
|
* @param modifier Modifier AST node.
|
|
10766
10765
|
* @param valueFormat Value format for the modifier.
|
|
10766
|
+
* @param valueFormatFlags Optional; RegExp flags for the value format.
|
|
10767
10767
|
*
|
|
10768
10768
|
* @returns Validation result.
|
|
10769
10769
|
*/
|
|
10770
|
-
const validateValue = (modifier, valueFormat) => {
|
|
10770
|
+
const validateValue = (modifier, valueFormat, valueFormatFlags) => {
|
|
10771
10771
|
if (isCustomValueFormatValidator(valueFormat)) {
|
|
10772
10772
|
const validator = CUSTOM_VALUE_FORMAT_MAP[valueFormat];
|
|
10773
10773
|
return validator(modifier);
|
|
@@ -10776,14 +10776,19 @@ const validateValue = (modifier, valueFormat) => {
|
|
|
10776
10776
|
if (!modifier.value?.value) {
|
|
10777
10777
|
return getValueRequiredValidationResult(modifierName);
|
|
10778
10778
|
}
|
|
10779
|
-
let
|
|
10779
|
+
let regExp;
|
|
10780
10780
|
try {
|
|
10781
|
-
|
|
10781
|
+
if (isString(valueFormatFlags)) {
|
|
10782
|
+
regExp = new RegExp(valueFormat, valueFormatFlags);
|
|
10783
|
+
}
|
|
10784
|
+
else {
|
|
10785
|
+
regExp = new RegExp(valueFormat);
|
|
10786
|
+
}
|
|
10782
10787
|
}
|
|
10783
10788
|
catch (e) {
|
|
10784
10789
|
throw new Error(`${SOURCE_DATA_ERROR_PREFIX.INVALID_VALUE_FORMAT_REGEXP}: '${modifierName}'`);
|
|
10785
10790
|
}
|
|
10786
|
-
const isValid =
|
|
10791
|
+
const isValid = regExp.test(modifier.value?.value);
|
|
10787
10792
|
if (!isValid) {
|
|
10788
10793
|
return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.VALUE_INVALID}: '${modifierName}'`);
|
|
10789
10794
|
}
|
|
@@ -11367,7 +11372,7 @@ const validateForSpecificSyntax = (syntax, modifier, isException) => {
|
|
|
11367
11372
|
if (!specificBlockerData.valueFormat) {
|
|
11368
11373
|
throw new Error(`${SOURCE_DATA_ERROR_PREFIX.NO_VALUE_FORMAT_FOR_ASSIGNABLE}: '${modifierName}'`);
|
|
11369
11374
|
}
|
|
11370
|
-
return validateValue(modifier, specificBlockerData.valueFormat);
|
|
11375
|
+
return validateValue(modifier, specificBlockerData.valueFormat, specificBlockerData.valueFormatFlags);
|
|
11371
11376
|
}
|
|
11372
11377
|
if (modifier?.value) {
|
|
11373
11378
|
// e.g. 'third-party=true'
|
|
@@ -13064,8 +13069,14 @@ function getErrorMessage(error) {
|
|
|
13064
13069
|
* Known validators that don't need to be validated as regex.
|
|
13065
13070
|
*/
|
|
13066
13071
|
const KNOWN_VALIDATORS = new Set([
|
|
13072
|
+
'csp_value',
|
|
13067
13073
|
'domain',
|
|
13074
|
+
'permissions_value',
|
|
13075
|
+
'pipe_separated_apps',
|
|
13076
|
+
'pipe_separated_denyallow_domains',
|
|
13068
13077
|
'pipe_separated_domains',
|
|
13078
|
+
'pipe_separated_methods',
|
|
13079
|
+
'pipe_separated_stealth_options',
|
|
13069
13080
|
'regexp',
|
|
13070
13081
|
'url',
|
|
13071
13082
|
]);
|
|
@@ -13116,6 +13127,10 @@ zodToCamelCase(baseCompatibilityDataSchema.extend({
|
|
|
13116
13127
|
* Its value can be a regex pattern or a known validator name (e.g. `domain`, `pipe_separated_domains`, etc.).
|
|
13117
13128
|
*/
|
|
13118
13129
|
value_format: nonEmptyStringSchema.nullable().default(null),
|
|
13130
|
+
/**
|
|
13131
|
+
* Describes the flags for the `value_format` regex pattern.
|
|
13132
|
+
*/
|
|
13133
|
+
value_format_flags: nonEmptyStringSchema.nullable().default(null),
|
|
13119
13134
|
}).superRefine((data, ctx) => {
|
|
13120
13135
|
// TODO: find something better, for now we can't add refine logic to the base schema:
|
|
13121
13136
|
// https://github.com/colinhacks/zod/issues/454#issuecomment-848370721
|
|
@@ -13136,11 +13151,17 @@ zodToCamelCase(baseCompatibilityDataSchema.extend({
|
|
|
13136
13151
|
const valueFormat = data.value_format.trim();
|
|
13137
13152
|
// if it is a known validator, we don't need to validate it further
|
|
13138
13153
|
if (KNOWN_VALIDATORS.has(valueFormat)) {
|
|
13154
|
+
if (data.value_format_flags) {
|
|
13155
|
+
ctx.addIssue({
|
|
13156
|
+
code: zod.ZodIssueCode.custom,
|
|
13157
|
+
message: 'value_format_flags are not allowed for known validators',
|
|
13158
|
+
});
|
|
13159
|
+
}
|
|
13139
13160
|
return;
|
|
13140
13161
|
}
|
|
13141
13162
|
// otherwise, we need to validate it as a regex
|
|
13142
13163
|
try {
|
|
13143
|
-
|
|
13164
|
+
new RegExp(valueFormat, data.value_format_flags ?? EMPTY);
|
|
13144
13165
|
}
|
|
13145
13166
|
catch (error) {
|
|
13146
13167
|
ctx.addIssue({
|
|
@@ -13149,6 +13170,12 @@ zodToCamelCase(baseCompatibilityDataSchema.extend({
|
|
|
13149
13170
|
});
|
|
13150
13171
|
}
|
|
13151
13172
|
}
|
|
13173
|
+
else if (data.value_format_flags) {
|
|
13174
|
+
ctx.addIssue({
|
|
13175
|
+
code: zod.ZodIssueCode.custom,
|
|
13176
|
+
message: 'value_format is required for value_format_flags',
|
|
13177
|
+
});
|
|
13178
|
+
}
|
|
13152
13179
|
}));
|
|
13153
13180
|
|
|
13154
13181
|
/**
|
|
@@ -15699,7 +15726,7 @@ class RuleCategorizer {
|
|
|
15699
15726
|
}
|
|
15700
15727
|
}
|
|
15701
15728
|
|
|
15702
|
-
const version = "2.
|
|
15729
|
+
const version = "2.2.0";
|
|
15703
15730
|
|
|
15704
15731
|
/**
|
|
15705
15732
|
* @file AGTree version
|
package/dist/agtree.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v2.
|
|
2
|
+
* AGTree v2.2.0 (build date: Wed, 27 Nov 2024 16:28:27 GMT)
|
|
3
3
|
* (c) 2024 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -12,7 +12,6 @@ import { TokenType as TokenType$1, tokenizeExtended, getFormattedTokenName } fro
|
|
|
12
12
|
import * as tldts from 'tldts';
|
|
13
13
|
import { parse } from 'tldts';
|
|
14
14
|
import isIp from 'is-ip';
|
|
15
|
-
import XRegExp from 'xregexp';
|
|
16
15
|
import cloneDeep from 'clone-deep';
|
|
17
16
|
import { modifiersCompatibilityTableData, redirectsCompatibilityTableData, scriptletsCompatibilityTableData } from './compatibility-table-data.js';
|
|
18
17
|
import zod from 'zod';
|
|
@@ -10744,10 +10743,11 @@ const isCustomValueFormatValidator = (valueFormat) => {
|
|
|
10744
10743
|
*
|
|
10745
10744
|
* @param modifier Modifier AST node.
|
|
10746
10745
|
* @param valueFormat Value format for the modifier.
|
|
10746
|
+
* @param valueFormatFlags Optional; RegExp flags for the value format.
|
|
10747
10747
|
*
|
|
10748
10748
|
* @returns Validation result.
|
|
10749
10749
|
*/
|
|
10750
|
-
const validateValue = (modifier, valueFormat) => {
|
|
10750
|
+
const validateValue = (modifier, valueFormat, valueFormatFlags) => {
|
|
10751
10751
|
if (isCustomValueFormatValidator(valueFormat)) {
|
|
10752
10752
|
const validator = CUSTOM_VALUE_FORMAT_MAP[valueFormat];
|
|
10753
10753
|
return validator(modifier);
|
|
@@ -10756,14 +10756,19 @@ const validateValue = (modifier, valueFormat) => {
|
|
|
10756
10756
|
if (!modifier.value?.value) {
|
|
10757
10757
|
return getValueRequiredValidationResult(modifierName);
|
|
10758
10758
|
}
|
|
10759
|
-
let
|
|
10759
|
+
let regExp;
|
|
10760
10760
|
try {
|
|
10761
|
-
|
|
10761
|
+
if (isString(valueFormatFlags)) {
|
|
10762
|
+
regExp = new RegExp(valueFormat, valueFormatFlags);
|
|
10763
|
+
}
|
|
10764
|
+
else {
|
|
10765
|
+
regExp = new RegExp(valueFormat);
|
|
10766
|
+
}
|
|
10762
10767
|
}
|
|
10763
10768
|
catch (e) {
|
|
10764
10769
|
throw new Error(`${SOURCE_DATA_ERROR_PREFIX.INVALID_VALUE_FORMAT_REGEXP}: '${modifierName}'`);
|
|
10765
10770
|
}
|
|
10766
|
-
const isValid =
|
|
10771
|
+
const isValid = regExp.test(modifier.value?.value);
|
|
10767
10772
|
if (!isValid) {
|
|
10768
10773
|
return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.VALUE_INVALID}: '${modifierName}'`);
|
|
10769
10774
|
}
|
|
@@ -11347,7 +11352,7 @@ const validateForSpecificSyntax = (syntax, modifier, isException) => {
|
|
|
11347
11352
|
if (!specificBlockerData.valueFormat) {
|
|
11348
11353
|
throw new Error(`${SOURCE_DATA_ERROR_PREFIX.NO_VALUE_FORMAT_FOR_ASSIGNABLE}: '${modifierName}'`);
|
|
11349
11354
|
}
|
|
11350
|
-
return validateValue(modifier, specificBlockerData.valueFormat);
|
|
11355
|
+
return validateValue(modifier, specificBlockerData.valueFormat, specificBlockerData.valueFormatFlags);
|
|
11351
11356
|
}
|
|
11352
11357
|
if (modifier?.value) {
|
|
11353
11358
|
// e.g. 'third-party=true'
|
|
@@ -13044,8 +13049,14 @@ function getErrorMessage(error) {
|
|
|
13044
13049
|
* Known validators that don't need to be validated as regex.
|
|
13045
13050
|
*/
|
|
13046
13051
|
const KNOWN_VALIDATORS = new Set([
|
|
13052
|
+
'csp_value',
|
|
13047
13053
|
'domain',
|
|
13054
|
+
'permissions_value',
|
|
13055
|
+
'pipe_separated_apps',
|
|
13056
|
+
'pipe_separated_denyallow_domains',
|
|
13048
13057
|
'pipe_separated_domains',
|
|
13058
|
+
'pipe_separated_methods',
|
|
13059
|
+
'pipe_separated_stealth_options',
|
|
13049
13060
|
'regexp',
|
|
13050
13061
|
'url',
|
|
13051
13062
|
]);
|
|
@@ -13096,6 +13107,10 @@ zodToCamelCase(baseCompatibilityDataSchema.extend({
|
|
|
13096
13107
|
* Its value can be a regex pattern or a known validator name (e.g. `domain`, `pipe_separated_domains`, etc.).
|
|
13097
13108
|
*/
|
|
13098
13109
|
value_format: nonEmptyStringSchema.nullable().default(null),
|
|
13110
|
+
/**
|
|
13111
|
+
* Describes the flags for the `value_format` regex pattern.
|
|
13112
|
+
*/
|
|
13113
|
+
value_format_flags: nonEmptyStringSchema.nullable().default(null),
|
|
13099
13114
|
}).superRefine((data, ctx) => {
|
|
13100
13115
|
// TODO: find something better, for now we can't add refine logic to the base schema:
|
|
13101
13116
|
// https://github.com/colinhacks/zod/issues/454#issuecomment-848370721
|
|
@@ -13116,11 +13131,17 @@ zodToCamelCase(baseCompatibilityDataSchema.extend({
|
|
|
13116
13131
|
const valueFormat = data.value_format.trim();
|
|
13117
13132
|
// if it is a known validator, we don't need to validate it further
|
|
13118
13133
|
if (KNOWN_VALIDATORS.has(valueFormat)) {
|
|
13134
|
+
if (data.value_format_flags) {
|
|
13135
|
+
ctx.addIssue({
|
|
13136
|
+
code: zod.ZodIssueCode.custom,
|
|
13137
|
+
message: 'value_format_flags are not allowed for known validators',
|
|
13138
|
+
});
|
|
13139
|
+
}
|
|
13119
13140
|
return;
|
|
13120
13141
|
}
|
|
13121
13142
|
// otherwise, we need to validate it as a regex
|
|
13122
13143
|
try {
|
|
13123
|
-
|
|
13144
|
+
new RegExp(valueFormat, data.value_format_flags ?? EMPTY);
|
|
13124
13145
|
}
|
|
13125
13146
|
catch (error) {
|
|
13126
13147
|
ctx.addIssue({
|
|
@@ -13129,6 +13150,12 @@ zodToCamelCase(baseCompatibilityDataSchema.extend({
|
|
|
13129
13150
|
});
|
|
13130
13151
|
}
|
|
13131
13152
|
}
|
|
13153
|
+
else if (data.value_format_flags) {
|
|
13154
|
+
ctx.addIssue({
|
|
13155
|
+
code: zod.ZodIssueCode.custom,
|
|
13156
|
+
message: 'value_format is required for value_format_flags',
|
|
13157
|
+
});
|
|
13158
|
+
}
|
|
13132
13159
|
}));
|
|
13133
13160
|
|
|
13134
13161
|
/**
|
|
@@ -15679,7 +15706,7 @@ class RuleCategorizer {
|
|
|
15679
15706
|
}
|
|
15680
15707
|
}
|
|
15681
15708
|
|
|
15682
|
-
const version = "2.
|
|
15709
|
+
const version = "2.2.0";
|
|
15683
15710
|
|
|
15684
15711
|
/**
|
|
15685
15712
|
* @file AGTree version
|