@adguard/hostlist-compiler 2.0.0 → 2.1.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.
@@ -0,0 +1,331 @@
1
+ const {
2
+ ACTION,
3
+ parseIpPattern,
4
+ normalizeFullIp,
5
+ check3OctetSubnet,
6
+ processIpRule,
7
+ normalizeIpRules,
8
+ } = require('../../src/transformations/ip-normalize');
9
+
10
+ describe('ip-normalize', () => {
11
+ describe('parseIpPattern', () => {
12
+ it('parses full IP without separators', () => {
13
+ const result = parseIpPattern('1.2.3.4');
14
+ expect(result).toEqual({
15
+ prefix: '',
16
+ octets: ['1', '2', '3', '4'],
17
+ hasTrailingDot: false,
18
+ hasTrailingWildcard: false,
19
+ hasCaret: false,
20
+ hasCaretPipe: false,
21
+ });
22
+ });
23
+
24
+ it('parses full IP with || and ^', () => {
25
+ const result = parseIpPattern('||1.2.3.4^');
26
+ expect(result).toEqual({
27
+ prefix: '||',
28
+ octets: ['1', '2', '3', '4'],
29
+ hasTrailingDot: false,
30
+ hasTrailingWildcard: false,
31
+ hasCaret: true,
32
+ hasCaretPipe: false,
33
+ });
34
+ });
35
+
36
+ it('parses full IP with | and ^', () => {
37
+ const result = parseIpPattern('|1.2.3.4^');
38
+ expect(result).toEqual({
39
+ prefix: '|',
40
+ octets: ['1', '2', '3', '4'],
41
+ hasTrailingDot: false,
42
+ hasTrailingWildcard: false,
43
+ hasCaret: true,
44
+ hasCaretPipe: false,
45
+ });
46
+ });
47
+
48
+ it('parses 3-octet subnet with trailing dot', () => {
49
+ const result = parseIpPattern('192.168.1.');
50
+ expect(result).toEqual({
51
+ prefix: '',
52
+ octets: ['192', '168', '1'],
53
+ hasTrailingDot: true,
54
+ hasTrailingWildcard: false,
55
+ hasCaret: false,
56
+ hasCaretPipe: false,
57
+ });
58
+ });
59
+
60
+ it('parses 3-octet subnet with trailing wildcard', () => {
61
+ const result = parseIpPattern('||192.168.1.*');
62
+ expect(result).toEqual({
63
+ prefix: '||',
64
+ octets: ['192', '168', '1'],
65
+ hasTrailingDot: false,
66
+ hasTrailingWildcard: true,
67
+ hasCaret: false,
68
+ hasCaretPipe: false,
69
+ });
70
+ });
71
+
72
+ it('parses pattern with ^|', () => {
73
+ const result = parseIpPattern('||1.2.3.4^|');
74
+ expect(result).toEqual({
75
+ prefix: '||',
76
+ octets: ['1', '2', '3', '4'],
77
+ hasTrailingDot: false,
78
+ hasTrailingWildcard: false,
79
+ hasCaret: true,
80
+ hasCaretPipe: true,
81
+ });
82
+ });
83
+
84
+ it('returns null for non-IP patterns', () => {
85
+ expect(parseIpPattern('example.com')).toBeNull();
86
+ expect(parseIpPattern('||example.com^')).toBeNull();
87
+ expect(parseIpPattern('1.2.3.4.5')).toBeNull();
88
+ expect(parseIpPattern('1.2.3.256')).toBeNull();
89
+ expect(parseIpPattern('1.2.3.abc')).toBeNull();
90
+ });
91
+ });
92
+
93
+ describe('normalizeFullIp', () => {
94
+ it('normalizes IP without separators', () => {
95
+ expect(normalizeFullIp('1.2.3.4')).toBe('||1.2.3.4^');
96
+ });
97
+
98
+ it('normalizes IP with only ^', () => {
99
+ expect(normalizeFullIp('1.2.3.4^')).toBe('||1.2.3.4^');
100
+ });
101
+
102
+ it('normalizes IP with only |', () => {
103
+ expect(normalizeFullIp('|1.2.3.4')).toBe('||1.2.3.4^');
104
+ });
105
+
106
+ it('normalizes IP with | and ^', () => {
107
+ expect(normalizeFullIp('|1.2.3.4^')).toBe('||1.2.3.4^');
108
+ });
109
+
110
+ it('normalizes IP with ^|', () => {
111
+ expect(normalizeFullIp('1.2.3.4^|')).toBe('||1.2.3.4^');
112
+ });
113
+
114
+ it('normalizes IP with | and ^|', () => {
115
+ expect(normalizeFullIp('|1.2.3.4^|')).toBe('||1.2.3.4^');
116
+ });
117
+
118
+ it('normalizes IP with only ||', () => {
119
+ expect(normalizeFullIp('||1.2.3.4')).toBe('||1.2.3.4^');
120
+ });
121
+
122
+ it('returns null for already correct format', () => {
123
+ expect(normalizeFullIp('||1.2.3.4^')).toBeNull();
124
+ });
125
+
126
+ it('returns null for 3-octet patterns', () => {
127
+ expect(normalizeFullIp('192.168.1.')).toBeNull();
128
+ expect(normalizeFullIp('||192.168.1.*')).toBeNull();
129
+ });
130
+
131
+ it('returns null for non-IP patterns', () => {
132
+ expect(normalizeFullIp('example.com')).toBeNull();
133
+ });
134
+ });
135
+
136
+ describe('check3OctetSubnet', () => {
137
+ it('allows 3-octet with trailing dot', () => {
138
+ expect(check3OctetSubnet('192.168.1.')).toEqual({
139
+ action: ACTION.NORMALIZE,
140
+ normalized: '||192.168.1.',
141
+ });
142
+ });
143
+
144
+ it('allows 3-octet with trailing wildcard', () => {
145
+ expect(check3OctetSubnet('192.168.1.*')).toEqual({
146
+ action: ACTION.NORMALIZE,
147
+ normalized: '||192.168.1.*',
148
+ });
149
+ });
150
+
151
+ it('normalizes 3-octet with single | and trailing dot', () => {
152
+ expect(check3OctetSubnet('|192.168.1.')).toEqual({
153
+ action: ACTION.NORMALIZE,
154
+ normalized: '||192.168.1.',
155
+ });
156
+ });
157
+
158
+ it('normalizes 3-octet with single | and trailing wildcard', () => {
159
+ expect(check3OctetSubnet('|192.168.1.*')).toEqual({
160
+ action: ACTION.NORMALIZE,
161
+ normalized: '||192.168.1.*',
162
+ });
163
+ });
164
+
165
+ it('allows 3-octet with || and trailing dot', () => {
166
+ expect(check3OctetSubnet('||192.168.1.')).toEqual({
167
+ action: ACTION.ALLOW,
168
+ });
169
+ });
170
+
171
+ it('allows 3-octet with || and trailing wildcard', () => {
172
+ expect(check3OctetSubnet('||192.168.1.*')).toEqual({
173
+ action: ACTION.ALLOW,
174
+ });
175
+ });
176
+
177
+ it('does not apply to 4-octet patterns', () => {
178
+ expect(check3OctetSubnet('1.2.3.4')).toBeNull();
179
+ expect(check3OctetSubnet('||1.2.3.4^')).toBeNull();
180
+ });
181
+
182
+ it('does not apply to non-3-octet patterns', () => {
183
+ expect(check3OctetSubnet('192.168.')).toBeNull();
184
+ });
185
+ });
186
+
187
+ // processIpRule — only tests logic unique to this function:
188
+ // @@-prefix handling, $modifier extraction, comments/empty lines, domain passthrough.
189
+ // Pattern-level normalize/reject/allow decisions are covered by helper tests above.
190
+ describe('processIpRule', () => {
191
+ it('keeps comments and empty lines', () => {
192
+ expect(processIpRule('! comment')).toEqual({ action: ACTION.KEEP });
193
+ expect(processIpRule('# comment')).toEqual({ action: ACTION.KEEP });
194
+ expect(processIpRule('')).toEqual({ action: ACTION.KEEP });
195
+ expect(processIpRule(' ')).toEqual({ action: ACTION.KEEP });
196
+ });
197
+
198
+ it('keeps domain rules unchanged', () => {
199
+ expect(processIpRule('||example.com^')).toEqual({ action: ACTION.KEEP });
200
+ expect(processIpRule('example.com')).toEqual({ action: ACTION.KEEP });
201
+ });
202
+
203
+ it('preserves modifiers during normalization', () => {
204
+ expect(processIpRule('1.2.3.4$important')).toEqual({
205
+ action: ACTION.NORMALIZE,
206
+ normalized: '||1.2.3.4^$important',
207
+ });
208
+ expect(processIpRule('@@1.2.3.4$important')).toEqual({
209
+ action: ACTION.NORMALIZE,
210
+ normalized: '@@||1.2.3.4^$important',
211
+ });
212
+ });
213
+
214
+ it('normalizes single-pipe 3-octet subnet to ||', () => {
215
+ expect(processIpRule('|192.168.1.')).toEqual({
216
+ action: ACTION.NORMALIZE,
217
+ normalized: '||192.168.1.',
218
+ });
219
+ expect(processIpRule('|192.168.1.*')).toEqual({
220
+ action: ACTION.NORMALIZE,
221
+ normalized: '||192.168.1.*',
222
+ });
223
+ });
224
+
225
+ it('normalizes IP rules with ^|', () => {
226
+ expect(processIpRule('1.2.3.4^|')).toEqual({
227
+ action: ACTION.NORMALIZE,
228
+ normalized: '||1.2.3.4^',
229
+ });
230
+ expect(processIpRule('|1.2.3.4^|')).toEqual({
231
+ action: ACTION.NORMALIZE,
232
+ normalized: '||1.2.3.4^',
233
+ });
234
+ expect(processIpRule('||1.2.3.4^|')).toEqual({
235
+ action: ACTION.NORMALIZE,
236
+ normalized: '||1.2.3.4^',
237
+ });
238
+ });
239
+
240
+ it('normalizes exception rules (@@)', () => {
241
+ expect(processIpRule('@@1.2.3.4')).toEqual({
242
+ action: ACTION.NORMALIZE,
243
+ normalized: '@@||1.2.3.4^',
244
+ });
245
+ expect(processIpRule('@@|1.2.3.4^')).toEqual({
246
+ action: ACTION.NORMALIZE,
247
+ normalized: '@@||1.2.3.4^',
248
+ });
249
+ expect(processIpRule('@@||1.2.3.4')).toEqual({
250
+ action: ACTION.NORMALIZE,
251
+ normalized: '@@||1.2.3.4^',
252
+ });
253
+ expect(processIpRule('@@192.168.1.')).toEqual({
254
+ action: ACTION.NORMALIZE,
255
+ normalized: '@@||192.168.1.',
256
+ });
257
+ // already correct — keep as-is
258
+ expect(processIpRule('@@||1.2.3.4^')).toEqual({ action: ACTION.KEEP });
259
+ expect(processIpRule('@@||192.168.1.')).toEqual({ action: ACTION.KEEP });
260
+ });
261
+
262
+ it('does not reject invalid @@-patterns — normalization-only, validateAllowIp will reject', () => {
263
+ // processIpRule cannot normalize these, so it keeps them unchanged.
264
+ // Rejection is the sole responsibility of the validator (validate.js),
265
+ // not of the normalizer — that eliminates double-rejection.
266
+ expect(processIpRule('@@192.168.1').action).toBe(ACTION.KEEP);
267
+ expect(processIpRule('@@||192.168.1^').action).toBe(ACTION.KEEP);
268
+ expect(processIpRule('@@1.2.').action).toBe(ACTION.KEEP);
269
+ expect(processIpRule('@@||10^').action).toBe(ACTION.KEEP);
270
+ });
271
+ });
272
+
273
+ // normalizeIpRules — one integration test with a mixed list covering
274
+ // normalize, reject, keep, @@, and modifiers in a single scenario.
275
+ describe('normalizeIpRules', () => {
276
+ it('processes a mixed list of rules', () => {
277
+ const rules = [
278
+ // keep
279
+ '! comment',
280
+ '||5.6.7.8^',
281
+ '||example.com^',
282
+ // normalize
283
+ '1.2.3.4',
284
+ '1.2.3.4^|',
285
+ '192.168.1.',
286
+ '1.2.3.4$important',
287
+ '5.6.7.8$client=192.168.1.1',
288
+ '|1.2.3.4^|',
289
+ // normalize @@
290
+ '@@1.2.3.4',
291
+ '@@1.2.3.4^|',
292
+ '@@|5.6.7.8^',
293
+ '@@192.168.1.',
294
+ // normalizeIpRules cannot normalize these — passes them through unchanged.
295
+ // validateAllowIp's validator is the single place responsible for rejecting
296
+ // invalid patterns (separation of concerns, no double-rejection).
297
+ '192.168.1',
298
+ '||1.2.3.4^',
299
+ '||192.168^',
300
+ '1.2.',
301
+ '@@192.168.1',
302
+ '@@1.2.',
303
+ '@@||10.0.1^',
304
+ ];
305
+ const result = normalizeIpRules(rules);
306
+ expect(result).toEqual([
307
+ '! comment',
308
+ '||5.6.7.8^',
309
+ '||example.com^',
310
+ '||1.2.3.4^',
311
+ '||1.2.3.4^',
312
+ '||192.168.1.',
313
+ '||1.2.3.4^$important',
314
+ '||5.6.7.8^$client=192.168.1.1',
315
+ '||1.2.3.4^',
316
+ '@@||1.2.3.4^',
317
+ '@@||1.2.3.4^',
318
+ '@@||5.6.7.8^',
319
+ '@@||192.168.1.',
320
+ // normalizer passes invalid patterns through; validator rejects them
321
+ '192.168.1',
322
+ '||1.2.3.4^',
323
+ '||192.168^',
324
+ '1.2.',
325
+ '@@192.168.1',
326
+ '@@1.2.',
327
+ '@@||10.0.1^',
328
+ ]);
329
+ });
330
+ });
331
+ });
@@ -59,7 +59,13 @@ dupl1
59
59
  it.each([
60
60
  ['Validate + ValidateAllowIp', ['Validate', 'ValidateAllowIp']],
61
61
  ['Validate + ValidateAllowPublicSuffix', ['Validate', 'ValidateAllowPublicSuffix']],
62
+ ['Validate + ValidateAllowIpAndPublicSuffix', ['Validate', 'ValidateAllowIpAndPublicSuffix']],
62
63
  ['ValidateAllowIp + ValidateAllowPublicSuffix', ['ValidateAllowIp', 'ValidateAllowPublicSuffix']],
64
+ ['ValidateAllowIp + ValidateAllowIpAndPublicSuffix', ['ValidateAllowIp', 'ValidateAllowIpAndPublicSuffix']],
65
+ [
66
+ 'ValidateAllowPublicSuffix + ValidateAllowIpAndPublicSuffix',
67
+ ['ValidateAllowPublicSuffix', 'ValidateAllowIpAndPublicSuffix'],
68
+ ],
63
69
  [
64
70
  'Validate + ValidateAllowIp + ValidateAllowPublicSuffix',
65
71
  ['Validate', 'ValidateAllowIp', 'ValidateAllowPublicSuffix'],
@@ -0,0 +1,167 @@
1
+ const { validateAllowIpAndPublicSuffix } = require('../../src/transformations/validate-allow-ip-and-public-suffix');
2
+
3
+ describe('ValidateAllowIpAndPublicSuffix', () => {
4
+ it('keeps valid domain rules', () => {
5
+ const rules = [
6
+ '||example.org^',
7
+ '||example.com^',
8
+ ];
9
+ const filtered = validateAllowIpAndPublicSuffix(rules);
10
+
11
+ expect(filtered).toEqual([
12
+ '||example.org^',
13
+ '||example.com^',
14
+ ]);
15
+ });
16
+
17
+ it('keeps IP address rules (like ValidateAllowIp)', () => {
18
+ const rules = [
19
+ '||185.149.120.173^',
20
+ '0.0.0.0 example.org',
21
+ ];
22
+ const filtered = validateAllowIpAndPublicSuffix(rules);
23
+
24
+ expect(filtered).toEqual([
25
+ '||185.149.120.173^',
26
+ '0.0.0.0 example.org',
27
+ ]);
28
+ });
29
+
30
+ it('keeps public suffix rules (like ValidateAllowPublicSuffix)', () => {
31
+ const rules = [
32
+ '||hl.cn^',
33
+ '||org^',
34
+ '||*.org^',
35
+ '.org^',
36
+ ];
37
+ const filtered = validateAllowIpAndPublicSuffix(rules);
38
+
39
+ expect(filtered).toEqual([
40
+ '||hl.cn^',
41
+ '||org^',
42
+ '||*.org^',
43
+ '.org^',
44
+ ]);
45
+ });
46
+
47
+ it('keeps both IP and public suffix rules together', () => {
48
+ const rules = [
49
+ '||185.149.120.173^',
50
+ '||org^',
51
+ '||example.org^',
52
+ '||hl.cn^',
53
+ '0.0.0.0 example.com',
54
+ ];
55
+ const filtered = validateAllowIpAndPublicSuffix(rules);
56
+
57
+ expect(filtered).toEqual([
58
+ '||185.149.120.173^',
59
+ '||org^',
60
+ '||example.org^',
61
+ '||hl.cn^',
62
+ '0.0.0.0 example.com',
63
+ ]);
64
+ });
65
+
66
+ it('normalizes IP patterns (like ValidateAllowIp)', () => {
67
+ const rules = [
68
+ '1.1.1.1^',
69
+ '192.168.1.1^',
70
+ '|1.1.1.1^',
71
+ '||192.168.1.',
72
+ '||192.168.1.*',
73
+ '||example.org^',
74
+ ];
75
+ const filtered = validateAllowIpAndPublicSuffix(rules);
76
+
77
+ expect(filtered).toEqual([
78
+ '||1.1.1.1^',
79
+ '||192.168.1.1^',
80
+ '||1.1.1.1^',
81
+ '||192.168.1.',
82
+ '||192.168.1.*',
83
+ '||example.org^',
84
+ ]);
85
+ });
86
+
87
+ it('rejects invalid rules', () => {
88
+ const rules = [
89
+ '||invalid/rule',
90
+ '||example.org^$domain=example.com',
91
+ '||example.org^',
92
+ ];
93
+ const filtered = validateAllowIpAndPublicSuffix(rules);
94
+
95
+ expect(filtered).toEqual([
96
+ '||example.org^',
97
+ ]);
98
+ });
99
+
100
+ it('rejects invalid IP patterns', () => {
101
+ const rules = [
102
+ // 3-octet without trailing dot — rejected (ambiguous)
103
+ '192.168.1',
104
+ '||192.168.1',
105
+ // 3-octet with ^ — rejected (doesn't work)
106
+ '||192.168.1^',
107
+ // 2-octet — rejected (too wide)
108
+ '||1.1.',
109
+ '1.1.',
110
+ // valid entries — kept
111
+ '||example.org^',
112
+ '||1.2.3.4^',
113
+ ];
114
+ const filtered = validateAllowIpAndPublicSuffix(rules);
115
+
116
+ expect(filtered).toEqual([
117
+ '||example.org^',
118
+ '||1.2.3.4^',
119
+ ]);
120
+ });
121
+
122
+ it('rejects terminated IDN TLDs (like ValidateAllowPublicSuffix)', () => {
123
+ const rules = [
124
+ '||*.xn--jlq61u9w7b^',
125
+ '||xn--jlq61u9w7b^',
126
+ '.xn--p1acf^',
127
+ '||*.xn--p1acf^',
128
+ ];
129
+ const filtered = validateAllowIpAndPublicSuffix(rules);
130
+
131
+ expect(filtered).toEqual([
132
+ '.xn--p1acf^',
133
+ '||*.xn--p1acf^',
134
+ ]);
135
+ });
136
+
137
+ it('keeps known ICANN TLDs but rejects unknown ones', () => {
138
+ const rules = [
139
+ '||aaa^',
140
+ '||aaaa^',
141
+ '||foo^',
142
+ '||zzzz^',
143
+ '||example.org^',
144
+ ];
145
+ const filtered = validateAllowIpAndPublicSuffix(rules);
146
+
147
+ expect(filtered).toEqual([
148
+ '||aaa^',
149
+ '||foo^',
150
+ '||example.org^',
151
+ ]);
152
+ });
153
+
154
+ it('removes preceding comments for invalid rules', () => {
155
+ const rules = `! rule comment
156
+
157
+ ||invalid/rule
158
+ ! comment
159
+ ||valid.com^`.split(/\r?\n/);
160
+ const filtered = validateAllowIpAndPublicSuffix(rules);
161
+
162
+ expect(filtered).toEqual([
163
+ '! comment',
164
+ '||valid.com^',
165
+ ]);
166
+ });
167
+ });
@@ -46,6 +46,8 @@ describe('ValidateAllowIp', () => {
46
46
  ||example.org^$third-party
47
47
  ||example.org^$important
48
48
  ||*.ga^$denyallow=example1.ga|example2.ga
49
+ 1.1.1.1$denyallow=001114.cn
50
+ ||1.1.1.1^$denyallow=001114.cn
49
51
  ://ww4.$denyallow=ww4.example.com
50
52
  ://example.org
51
53
  ||example.org^|
@@ -69,44 +71,70 @@ describe('ValidateAllowIp', () => {
69
71
  ]);
70
72
  });
71
73
 
72
- it('allows IP-subnet patterns but rejects IP-suffix patterns', () => {
73
- // ValidateAllowIp allows IP-subnet patterns (with | or || prefix) because they block specific subnets.
74
- // But IP-suffix patterns (no prefix) are ALWAYS rejected because they block unpredictably
75
- // (e.g., 1.1^ blocks 1.1.1.1, 1.1.111.1, example1.1).
74
+ it('normalizes and validates IP patterns', () => {
75
+ // ValidateAllowIp now normalizes incomplete IP rules to ||ip^ format
76
+ // and rejects patterns that don't work in AdGuard Home.
76
77
  const rules = [
77
- // IP-suffix (no prefix) — rejected ALWAYS (blocks unpredictably)
78
+ // IP-suffix (no prefix) with ^ — normalized to ||ip^ for 4 octets
79
+ '1.1.1.1^',
80
+ '192.168.1.1^',
81
+ // IP-suffix (no prefix) with ^ — rejected for <4 octets (doesn't work)
78
82
  '1.1^',
79
83
  '1.1.1^',
80
- '1.1.1.1^',
81
84
  '192.168^',
82
85
  '10.0.1^',
83
- '192.168.1.1^',
84
- // IP-subnet (with prefix) — allowed in ValidateAllowIp
86
+ // IP-subnet with ^ and <4 octets — rejected (doesn't work in AdGuard Home)
85
87
  '||1.1^',
86
88
  '|1.1^',
87
89
  '||1.1.1^',
88
90
  '|1.1.1^',
89
- '||1.1.1.1^',
90
- '|1.1.1.1^',
91
91
  '||192.168^',
92
92
  '||10.0.1^',
93
+ // Full 4-octet IPs — normalized to ||ip^
94
+ '||1.1.1.1^',
95
+ '|1.1.1.1^',
93
96
  '||192.168.1.1^',
97
+ '1.2.3.4^|',
98
+ '|1.2.3.4^|',
99
+ '||1.2.3.4^|',
100
+ // 3-octet subnet wildcards — allowed (all prefix forms normalize to ||)
101
+ '||192.168.1.',
102
+ '||192.168.1.*',
103
+ '|192.168.1.',
104
+ '|192.168.1.*',
105
+ '192.168.1.',
106
+ // 3-octet without trailing dot — rejected (ambiguous)
107
+ '192.168.1',
108
+ '||192.168.1',
109
+ // 2-octet patterns — rejected (too wide)
110
+ '||1.1.',
111
+ '1.1.',
112
+ // 4-octet with trailing dot or wildcard — rejected (malformed IP, not a complete address)
113
+ '1.2.3.4.',
114
+ '1.2.3.4.*',
115
+ '||1.2.3.4.',
116
+ '||1.2.3.4.*',
94
117
  // valid domain — kept
95
118
  '||example.org^',
96
119
  ];
97
120
  const filtered = validateAllowIp(rules);
98
121
 
99
122
  expect(filtered).toEqual([
100
- // IP-subnet patterns are allowed
101
- '||1.1^',
102
- '|1.1^',
103
- '||1.1.1^',
104
- '|1.1.1^',
123
+ // 4-octet IPs normalized to ||ip^
124
+ '||1.1.1.1^',
125
+ '||192.168.1.1^',
126
+ '||1.1.1.1^',
105
127
  '||1.1.1.1^',
106
- '|1.1.1.1^',
107
- '||192.168^',
108
- '||10.0.1^',
109
128
  '||192.168.1.1^',
129
+ '||1.2.3.4^',
130
+ '||1.2.3.4^',
131
+ '||1.2.3.4^',
132
+ // 3-octet subnet wildcards (all prefix forms normalized to ||)
133
+ '||192.168.1.',
134
+ '||192.168.1.*',
135
+ '||192.168.1.',
136
+ '||192.168.1.*',
137
+ '||192.168.1.',
110
138
  // valid domain
111
139
  '||example.org^',
112
140
  ]);
@@ -261,4 +261,24 @@ describe('validateAllowPublicSuffix', () => {
261
261
  '@@.xyz123notreal.org^',
262
262
  ]);
263
263
  });
264
+
265
+ it('rejects terminated/unknown IDN TLDs (xn-- prefixed) not in ICANN list', () => {
266
+ // xn--jlq61u9w7b (.蔚来) was terminated by ICANN in 2024.
267
+ // tldts reports it as non-ICANN public suffix, so whole-TLD rules should be rejected
268
+ // just like any other unknown single-label pattern.
269
+ const rules = [
270
+ '||*.xn--jlq61u9w7b^', // terminated IDN TLD — rejected
271
+ '||xn--jlq61u9w7b^', // same, without wildcard — rejected
272
+ '.xn--jlq61u9w7b^', // same, dot-prefix — rejected
273
+ '*.xn--jlq61u9w7b^', // same, wildcard-prefix — rejected
274
+ '.xn--p1acf^', // .рус — real ICANN TLD — kept
275
+ '||*.xn--p1acf^', // .рус — real ICANN TLD — kept
276
+ ];
277
+ const filtered = validateAllowPublicSuffix(rules);
278
+
279
+ expect(filtered).toEqual([
280
+ '.xn--p1acf^',
281
+ '||*.xn--p1acf^',
282
+ ]);
283
+ });
264
284
  });