@email-utils/validator-syntax 0.0.1-8 → 1.0.0-rc.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.
@@ -0,0 +1,2103 @@
1
+ import { createSyntaxValidator } from "./index.mjs";
2
+ //#region src/fixtures/types.ts
3
+ const presets = [
4
+ "practical",
5
+ "rfc5321",
6
+ "rfc5322",
7
+ "html5"
8
+ ];
9
+ /** The support matrix's rows, in order, with each feature's label. */
10
+ const syntaxFeatures = [
11
+ {
12
+ feature: "dot-atom",
13
+ label: "Letters, digits, and single dots"
14
+ },
15
+ {
16
+ feature: "atext-specials",
17
+ label: "Printable specials like `+`, `/`, `=`, and `_`"
18
+ },
19
+ {
20
+ feature: "route-chars",
21
+ label: "Route characters (`%`, `!`)"
22
+ },
23
+ {
24
+ feature: "misplaced-dots",
25
+ label: "Leading, trailing, or consecutive dots"
26
+ },
27
+ {
28
+ feature: "long-local",
29
+ label: "Local part over 64 characters"
30
+ },
31
+ {
32
+ feature: "quoted-local",
33
+ label: "Quoted local part"
34
+ },
35
+ {
36
+ feature: "quoted-pair",
37
+ label: "Backslash escapes in a quoted string"
38
+ },
39
+ {
40
+ feature: "obs-local",
41
+ label: "Dot-separated atoms and quoted strings mixed"
42
+ },
43
+ {
44
+ feature: "comments",
45
+ label: "Comments"
46
+ },
47
+ {
48
+ feature: "fws",
49
+ label: "Whitespace and line folding between tokens"
50
+ },
51
+ {
52
+ feature: "obs-control",
53
+ label: "Control characters (obsolete syntax)"
54
+ },
55
+ {
56
+ feature: "ipv4-literal",
57
+ label: "IPv4 address literal"
58
+ },
59
+ {
60
+ feature: "ipv6-literal",
61
+ label: "IPv6 address literal"
62
+ },
63
+ {
64
+ feature: "general-literal",
65
+ label: "Other domain literals"
66
+ },
67
+ {
68
+ feature: "dotless-domain",
69
+ label: "Domain with no dot"
70
+ },
71
+ {
72
+ feature: "unknown-tld",
73
+ label: "TLD outside the IANA set"
74
+ }
75
+ ];
76
+ const valid = { ok: true };
77
+ function fail(reason, index) {
78
+ return index === void 0 ? {
79
+ ok: false,
80
+ reason
81
+ } : {
82
+ ok: false,
83
+ reason,
84
+ index
85
+ };
86
+ }
87
+ /** The same result under every preset. */
88
+ function everywhere(expected) {
89
+ return {
90
+ practical: expected,
91
+ rfc5321: expected,
92
+ rfc5322: expected,
93
+ html5: expected
94
+ };
95
+ }
96
+ /** Valid under both RFC presets; `practical` and `html5` both give `rejected`. */
97
+ function rfcOnly(rejected) {
98
+ return {
99
+ practical: rejected,
100
+ rfc5321: valid,
101
+ rfc5322: valid,
102
+ html5: rejected
103
+ };
104
+ }
105
+ /** Fails the same way under every preset but rfc5322, which gives `rfc5322`. */
106
+ function allBut5322(others, rfc5322) {
107
+ return {
108
+ ...everywhere(others),
109
+ rfc5322
110
+ };
111
+ }
112
+ /** Valid only under `rfc5322`; every other preset gives `rejected`. */
113
+ function rfc5322Only(rejected) {
114
+ return {
115
+ ...everywhere(rejected),
116
+ rfc5322: valid
117
+ };
118
+ }
119
+ //#endregion
120
+ //#region src/fixtures/isemail.ts
121
+ /** A domain literal that only rfc5322's dtext accepts. */
122
+ const rfc5322Literal = {
123
+ practical: fail("syntax.domain.invalid_char", 5),
124
+ rfc5321: fail("syntax.domain.literal_invalid", 5),
125
+ rfc5322: valid,
126
+ html5: fail("syntax.domain.invalid_char", 5)
127
+ };
128
+ /** Quote-unaware presets fail at the opening quote; the RFC presets give `rfc`. */
129
+ function quotedLocal(rfc) {
130
+ return {
131
+ practical: fail("syntax.local.invalid_char", 0),
132
+ rfc5321: rfc,
133
+ rfc5322: rfc,
134
+ html5: fail("syntax.local.invalid_char", 0)
135
+ };
136
+ }
137
+ const longLabel = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl";
138
+ const isemailFixtures = [
139
+ {
140
+ isemail: 1,
141
+ address: "",
142
+ description: "Empty string",
143
+ expected: everywhere(fail("syntax.address.empty"))
144
+ },
145
+ {
146
+ isemail: 2,
147
+ address: "test",
148
+ description: "No @",
149
+ expected: everywhere(fail("syntax.address.no_at"))
150
+ },
151
+ {
152
+ isemail: 3,
153
+ address: "@",
154
+ description: "Only an @",
155
+ expected: everywhere(fail("syntax.local.empty"))
156
+ },
157
+ {
158
+ isemail: 4,
159
+ address: "test@",
160
+ description: "Nothing after the @",
161
+ expected: everywhere(fail("syntax.domain.empty"))
162
+ },
163
+ {
164
+ isemail: 5,
165
+ address: "test@io",
166
+ description: "Domain with no dot, a real TLD",
167
+ feature: "dotless-domain",
168
+ expected: {
169
+ ...everywhere(fail("syntax.domain.no_dot")),
170
+ html5: valid
171
+ }
172
+ },
173
+ {
174
+ isemail: 6,
175
+ address: "@io",
176
+ description: "Nothing before the @, dotless domain",
177
+ expected: everywhere(fail("syntax.local.empty"))
178
+ },
179
+ {
180
+ isemail: 7,
181
+ address: "@iana.org",
182
+ description: "Nothing before the @",
183
+ expected: everywhere(fail("syntax.local.empty"))
184
+ },
185
+ {
186
+ isemail: 8,
187
+ address: "test@iana.org",
188
+ description: "Simple address",
189
+ feature: "dot-atom",
190
+ expected: everywhere(valid)
191
+ },
192
+ {
193
+ isemail: 9,
194
+ address: "test@nominet.org.uk",
195
+ description: "Three-label domain",
196
+ feature: "dot-atom",
197
+ expected: everywhere(valid)
198
+ },
199
+ {
200
+ isemail: 10,
201
+ address: "test@about.museum",
202
+ description: "Six-letter TLD",
203
+ feature: "dot-atom",
204
+ expected: everywhere(valid)
205
+ },
206
+ {
207
+ isemail: 11,
208
+ address: "a@iana.org",
209
+ description: "Single-letter local part",
210
+ feature: "dot-atom",
211
+ expected: everywhere(valid)
212
+ },
213
+ {
214
+ isemail: 12,
215
+ address: "test@e.com",
216
+ description: "Single-letter domain label",
217
+ feature: "dot-atom",
218
+ expected: everywhere(valid)
219
+ },
220
+ {
221
+ isemail: 13,
222
+ address: "test@iana.a",
223
+ description: "Single-letter TLD",
224
+ feature: "unknown-tld",
225
+ expected: {
226
+ ...everywhere(valid),
227
+ practical: fail("syntax.tld.unknown")
228
+ }
229
+ },
230
+ {
231
+ isemail: 14,
232
+ address: "test.test@iana.org",
233
+ description: "Dot in the local part",
234
+ feature: "dot-atom",
235
+ expected: everywhere(valid)
236
+ },
237
+ {
238
+ isemail: 15,
239
+ address: ".test@iana.org",
240
+ description: "Local part starting with a dot",
241
+ feature: "misplaced-dots",
242
+ expected: {
243
+ ...everywhere(fail("syntax.local.invalid_char", 0)),
244
+ html5: valid
245
+ }
246
+ },
247
+ {
248
+ isemail: 16,
249
+ address: "test.@iana.org",
250
+ description: "Local part ending with a dot",
251
+ feature: "misplaced-dots",
252
+ expected: {
253
+ ...everywhere(fail("syntax.local.invalid_char", 4)),
254
+ html5: valid
255
+ }
256
+ },
257
+ {
258
+ isemail: 17,
259
+ address: "test..iana.org",
260
+ description: "No @, consecutive dots",
261
+ expected: everywhere(fail("syntax.address.no_at"))
262
+ },
263
+ {
264
+ isemail: 18,
265
+ address: "test_exa-mple.com",
266
+ description: "No @, underscore and hyphen",
267
+ expected: everywhere(fail("syntax.address.no_at"))
268
+ },
269
+ {
270
+ isemail: 19,
271
+ address: "!#$%&`*+/=?^`{|}~@iana.org",
272
+ description: "Local part of printable specials only",
273
+ feature: "route-chars",
274
+ expected: {
275
+ ...everywhere(valid),
276
+ practical: fail("syntax.local.invalid_char", 0)
277
+ }
278
+ },
279
+ {
280
+ isemail: 20,
281
+ address: "test\\@test@iana.org",
282
+ description: "Backslash-escaped @ outside a quoted string",
283
+ expected: everywhere(fail("syntax.local.invalid_char", 4))
284
+ },
285
+ {
286
+ isemail: 21,
287
+ address: "123@iana.org",
288
+ description: "All-digit local part",
289
+ feature: "dot-atom",
290
+ expected: everywhere(valid)
291
+ },
292
+ {
293
+ isemail: 22,
294
+ address: "test@123.com",
295
+ description: "All-digit domain label",
296
+ feature: "dot-atom",
297
+ expected: everywhere(valid)
298
+ },
299
+ {
300
+ isemail: 23,
301
+ address: "test@iana.123",
302
+ description: "All-digit TLD",
303
+ feature: "unknown-tld",
304
+ expected: {
305
+ ...everywhere(valid),
306
+ practical: fail("syntax.tld.unknown")
307
+ }
308
+ },
309
+ {
310
+ isemail: 24,
311
+ address: "test@255.255.255.255",
312
+ description: "Dotted quad without brackets",
313
+ feature: "unknown-tld",
314
+ expected: {
315
+ ...everywhere(valid),
316
+ practical: fail("syntax.tld.unknown")
317
+ }
318
+ },
319
+ {
320
+ isemail: 25,
321
+ address: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@iana.org",
322
+ description: "Local part of exactly 64 characters",
323
+ feature: "dot-atom",
324
+ expected: everywhere(valid)
325
+ },
326
+ {
327
+ isemail: 26,
328
+ address: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklmn@iana.org",
329
+ description: "Local part of 65 characters",
330
+ feature: "long-local",
331
+ expected: {
332
+ practical: fail("syntax.local.too_long"),
333
+ rfc5321: fail("syntax.local.too_long"),
334
+ rfc5322: valid,
335
+ html5: valid
336
+ }
337
+ },
338
+ {
339
+ isemail: 27,
340
+ address: `test@${longLabel}.com`,
341
+ description: "Domain label of exactly 63 characters",
342
+ feature: "dot-atom",
343
+ expected: everywhere(valid)
344
+ },
345
+ {
346
+ isemail: 28,
347
+ address: `test@${longLabel}m.com`,
348
+ description: "Domain label of 64 characters",
349
+ expected: everywhere(fail("syntax.domain.label_invalid", 5))
350
+ },
351
+ {
352
+ isemail: 29,
353
+ address: "test@mason-dixon.com",
354
+ description: "Hyphen inside a domain label",
355
+ feature: "dot-atom",
356
+ expected: everywhere(valid)
357
+ },
358
+ {
359
+ isemail: 30,
360
+ address: "test@-iana.org",
361
+ description: "Domain label starting with a hyphen",
362
+ expected: everywhere(fail("syntax.domain.label_invalid", 5))
363
+ },
364
+ {
365
+ isemail: 31,
366
+ address: "test@iana-.com",
367
+ description: "Domain label ending with a hyphen",
368
+ expected: everywhere(fail("syntax.domain.label_invalid", 9))
369
+ },
370
+ {
371
+ isemail: 32,
372
+ address: "test@c--n.com",
373
+ description: "Consecutive hyphens inside a domain label",
374
+ feature: "dot-atom",
375
+ expected: everywhere(valid)
376
+ },
377
+ {
378
+ isemail: 33,
379
+ address: "test@iana.co-uk",
380
+ description: "Hyphenated TLD",
381
+ feature: "unknown-tld",
382
+ expected: {
383
+ ...everywhere(valid),
384
+ practical: fail("syntax.tld.unknown")
385
+ }
386
+ },
387
+ {
388
+ isemail: 34,
389
+ address: "test@.iana.org",
390
+ description: "Domain starting with a dot",
391
+ expected: everywhere(fail("syntax.domain.label_invalid", 5))
392
+ },
393
+ {
394
+ isemail: 35,
395
+ address: "test@iana.org.",
396
+ description: "Domain ending with a dot",
397
+ expected: everywhere(fail("syntax.domain.label_invalid", 13))
398
+ },
399
+ {
400
+ isemail: 36,
401
+ address: "test@iana..com",
402
+ description: "Consecutive dots in the domain",
403
+ expected: everywhere(fail("syntax.domain.label_invalid", 10))
404
+ },
405
+ {
406
+ isemail: 37,
407
+ address: "a@a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v",
408
+ description: "126 single-letter domain labels",
409
+ expected: {
410
+ ...everywhere(valid),
411
+ practical: fail("syntax.tld.unknown")
412
+ }
413
+ },
414
+ {
415
+ isemail: 38,
416
+ address: `abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@${longLabel}.${longLabel}.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi`,
417
+ description: "Address of exactly 254 characters",
418
+ expected: {
419
+ ...everywhere(valid),
420
+ practical: fail("syntax.tld.unknown")
421
+ }
422
+ },
423
+ {
424
+ isemail: 39,
425
+ address: `abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@${longLabel}.${longLabel}.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij`,
426
+ description: "Address of 255 characters",
427
+ expected: everywhere(fail("syntax.address.too_long"))
428
+ },
429
+ {
430
+ isemail: 40,
431
+ address: `a@${longLabel}.${longLabel}.${longLabel}.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.hij`,
432
+ description: "Domain of 255 characters",
433
+ expected: {
434
+ ...everywhere(fail("syntax.domain.too_long")),
435
+ html5: fail("syntax.address.too_long")
436
+ }
437
+ },
438
+ {
439
+ isemail: 41,
440
+ address: `a@${longLabel}.${longLabel}.${longLabel}.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.hijk`,
441
+ description: "Domain of 256 characters",
442
+ expected: {
443
+ ...everywhere(fail("syntax.domain.too_long")),
444
+ html5: fail("syntax.address.too_long")
445
+ }
446
+ },
447
+ {
448
+ isemail: 42,
449
+ address: "\"test\"@iana.org",
450
+ description: "Quoted local part",
451
+ feature: "quoted-local",
452
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
453
+ },
454
+ {
455
+ isemail: 43,
456
+ address: "\"\"@iana.org",
457
+ description: "Empty quoted local part",
458
+ feature: "quoted-local",
459
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
460
+ },
461
+ {
462
+ isemail: 44,
463
+ address: "\"\"\"@iana.org",
464
+ description: "Stray quote after an empty quoted string",
465
+ expected: quotedLocal(fail("syntax.local.invalid_char", 2))
466
+ },
467
+ {
468
+ isemail: 45,
469
+ address: "\"\\a\"@iana.org",
470
+ description: "Escaped letter in a quoted string",
471
+ feature: "quoted-pair",
472
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
473
+ },
474
+ {
475
+ isemail: 46,
476
+ address: "\"\\\"\"@iana.org",
477
+ description: "Escaped quote in a quoted string",
478
+ feature: "quoted-pair",
479
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
480
+ },
481
+ {
482
+ isemail: 47,
483
+ address: "\"\\\"@iana.org",
484
+ description: "Quoted string whose closing quote is escaped",
485
+ expected: quotedLocal(fail("syntax.address.no_at"))
486
+ },
487
+ {
488
+ isemail: 48,
489
+ address: "\"\\\\\"@iana.org",
490
+ description: "Escaped backslash in a quoted string",
491
+ feature: "quoted-pair",
492
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
493
+ },
494
+ {
495
+ isemail: 49,
496
+ address: "test\"@iana.org",
497
+ description: "Stray quote at the end of an atom",
498
+ expected: everywhere(fail("syntax.local.invalid_char", 4))
499
+ },
500
+ {
501
+ isemail: 50,
502
+ address: "\"test@iana.org",
503
+ description: "Unterminated quoted string",
504
+ expected: quotedLocal(fail("syntax.address.no_at"))
505
+ },
506
+ {
507
+ isemail: 51,
508
+ address: "\"test\"test@iana.org",
509
+ description: "Atom straight after a quoted string",
510
+ expected: quotedLocal(fail("syntax.local.invalid_char", 6))
511
+ },
512
+ {
513
+ isemail: 52,
514
+ address: "test\"text\"@iana.org",
515
+ description: "Quoted string straight after an atom",
516
+ expected: everywhere(fail("syntax.local.invalid_char", 4))
517
+ },
518
+ {
519
+ isemail: 53,
520
+ address: "\"test\"\"test\"@iana.org",
521
+ description: "Two quoted strings with no dot between",
522
+ expected: quotedLocal(fail("syntax.local.invalid_char", 6))
523
+ },
524
+ {
525
+ isemail: 54,
526
+ address: "\"test\".\"test\"@iana.org",
527
+ description: "Dot-separated quoted strings",
528
+ feature: "obs-local",
529
+ expected: {
530
+ ...quotedLocal(valid),
531
+ rfc5321: fail("syntax.local.invalid_char", 6)
532
+ }
533
+ },
534
+ {
535
+ isemail: 55,
536
+ address: "\"test\\ test\"@iana.org",
537
+ description: "Escaped space in a quoted string",
538
+ feature: "quoted-pair",
539
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
540
+ },
541
+ {
542
+ isemail: 56,
543
+ address: "\"test\".test@iana.org",
544
+ description: "Quoted string then a dot-separated atom",
545
+ feature: "obs-local",
546
+ expected: {
547
+ ...quotedLocal(valid),
548
+ rfc5321: fail("syntax.local.invalid_char", 6)
549
+ }
550
+ },
551
+ {
552
+ isemail: 57,
553
+ address: "\"test\0\"@iana.org",
554
+ description: "NUL in a quoted string",
555
+ expected: quotedLocal(fail("syntax.local.invalid_char", 5))
556
+ },
557
+ {
558
+ isemail: 58,
559
+ address: "\"test\\\0\"@iana.org",
560
+ description: "Escaped NUL in a quoted string",
561
+ feature: "obs-control",
562
+ expected: {
563
+ ...quotedLocal(valid),
564
+ rfc5321: fail("syntax.local.invalid_char", 6)
565
+ }
566
+ },
567
+ {
568
+ isemail: 59,
569
+ address: "\"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghj\"@iana.org",
570
+ description: "Quoted local part of 65 characters",
571
+ expected: {
572
+ ...quotedLocal(valid),
573
+ rfc5321: fail("syntax.local.too_long")
574
+ }
575
+ },
576
+ {
577
+ isemail: 60,
578
+ address: "\"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefg\\h\"@iana.org",
579
+ description: "Quoted local part of 65 characters with an escape",
580
+ expected: {
581
+ ...quotedLocal(valid),
582
+ rfc5321: fail("syntax.local.too_long")
583
+ }
584
+ },
585
+ {
586
+ isemail: 61,
587
+ address: "test@[255.255.255.255]",
588
+ description: "IPv4 address literal",
589
+ feature: "ipv4-literal",
590
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 5))
591
+ },
592
+ {
593
+ isemail: 62,
594
+ address: "test@a[255.255.255.255]",
595
+ description: "Domain literal after a label",
596
+ expected: everywhere(fail("syntax.domain.invalid_char", 6))
597
+ },
598
+ {
599
+ isemail: 63,
600
+ address: "test@[255.255.255]",
601
+ description: "IPv4 literal with three octets",
602
+ feature: "general-literal",
603
+ expected: rfc5322Literal
604
+ },
605
+ {
606
+ isemail: 64,
607
+ address: "test@[255.255.255.255.255]",
608
+ description: "IPv4 literal with five octets",
609
+ feature: "general-literal",
610
+ expected: rfc5322Literal
611
+ },
612
+ {
613
+ isemail: 65,
614
+ address: "test@[255.255.255.256]",
615
+ description: "IPv4 literal with an octet over 255",
616
+ feature: "general-literal",
617
+ expected: rfc5322Literal
618
+ },
619
+ {
620
+ isemail: 66,
621
+ address: "test@[1111:2222:3333:4444:5555:6666:7777:8888]",
622
+ description: "IPv6 literal without the IPv6 tag",
623
+ feature: "general-literal",
624
+ expected: rfc5322Literal
625
+ },
626
+ {
627
+ isemail: 67,
628
+ address: "test@[IPv6:1111:2222:3333:4444:5555:6666:7777]",
629
+ description: "IPv6 literal with seven groups",
630
+ feature: "general-literal",
631
+ expected: rfc5322Literal
632
+ },
633
+ {
634
+ isemail: 68,
635
+ address: "test@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]",
636
+ description: "IPv6 literal with eight groups",
637
+ feature: "ipv6-literal",
638
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 5))
639
+ },
640
+ {
641
+ isemail: 69,
642
+ address: "test@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]",
643
+ description: "IPv6 literal with nine groups",
644
+ feature: "general-literal",
645
+ expected: rfc5322Literal
646
+ },
647
+ {
648
+ isemail: 70,
649
+ address: "test@[IPv6:1111:2222:3333:4444:5555:6666:7777:888G]",
650
+ description: "IPv6 literal with a non-hex digit",
651
+ feature: "general-literal",
652
+ expected: rfc5322Literal
653
+ },
654
+ {
655
+ isemail: 71,
656
+ address: "test@[IPv6:1111:2222:3333:4444:5555:6666::8888]",
657
+ description: "IPv6 literal with :: standing for one group",
658
+ feature: "general-literal",
659
+ expected: rfc5322Literal
660
+ },
661
+ {
662
+ isemail: 72,
663
+ address: "test@[IPv6:1111:2222:3333:4444:5555::8888]",
664
+ description: "Compressed IPv6 literal",
665
+ feature: "ipv6-literal",
666
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 5))
667
+ },
668
+ {
669
+ isemail: 73,
670
+ address: "test@[IPv6:1111:2222:3333:4444:5555:6666::7777:8888]",
671
+ description: "Compressed IPv6 literal with eight groups",
672
+ feature: "general-literal",
673
+ expected: rfc5322Literal
674
+ },
675
+ {
676
+ isemail: 74,
677
+ address: "test@[IPv6::3333:4444:5555:6666:7777:8888]",
678
+ description: "IPv6 literal starting with a single colon",
679
+ feature: "general-literal",
680
+ expected: rfc5322Literal
681
+ },
682
+ {
683
+ isemail: 75,
684
+ address: "test@[IPv6:::3333:4444:5555:6666:7777:8888]",
685
+ description: "IPv6 literal starting with ::",
686
+ feature: "ipv6-literal",
687
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 5))
688
+ },
689
+ {
690
+ isemail: 76,
691
+ address: "test@[IPv6:1111::4444:5555::8888]",
692
+ description: "IPv6 literal with two ::",
693
+ feature: "general-literal",
694
+ expected: rfc5322Literal
695
+ },
696
+ {
697
+ isemail: 77,
698
+ address: "test@[IPv6:::]",
699
+ description: "IPv6 unspecified address literal",
700
+ feature: "ipv6-literal",
701
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 5))
702
+ },
703
+ {
704
+ isemail: 78,
705
+ address: "test@[IPv6:1111:2222:3333:4444:5555:255.255.255.255]",
706
+ description: "IPv4-in-IPv6 literal with five groups",
707
+ feature: "general-literal",
708
+ expected: rfc5322Literal
709
+ },
710
+ {
711
+ isemail: 79,
712
+ address: "test@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255]",
713
+ description: "IPv4-in-IPv6 literal with six groups",
714
+ feature: "ipv6-literal",
715
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 5))
716
+ },
717
+ {
718
+ isemail: 80,
719
+ address: "test@[IPv6:1111:2222:3333:4444:5555:6666:7777:255.255.255.255]",
720
+ description: "IPv4-in-IPv6 literal with seven groups",
721
+ feature: "general-literal",
722
+ expected: rfc5322Literal
723
+ },
724
+ {
725
+ isemail: 81,
726
+ address: "test@[IPv6:1111:2222:3333:4444::255.255.255.255]",
727
+ description: "Compressed IPv4-in-IPv6 literal",
728
+ feature: "ipv6-literal",
729
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 5))
730
+ },
731
+ {
732
+ isemail: 82,
733
+ address: "test@[IPv6:1111:2222:3333:4444:5555:6666::255.255.255.255]",
734
+ description: "Compressed IPv4-in-IPv6 literal with six groups",
735
+ feature: "general-literal",
736
+ expected: rfc5322Literal
737
+ },
738
+ {
739
+ isemail: 83,
740
+ address: "test@[IPv6:1111:2222:3333:4444:::255.255.255.255]",
741
+ description: "IPv4-in-IPv6 literal with :::",
742
+ feature: "general-literal",
743
+ expected: rfc5322Literal
744
+ },
745
+ {
746
+ isemail: 84,
747
+ address: "test@[IPv6::255.255.255.255]",
748
+ description: "IPv4-in-IPv6 literal starting with a single colon",
749
+ feature: "general-literal",
750
+ expected: rfc5322Literal
751
+ },
752
+ {
753
+ isemail: 85,
754
+ address: " test @iana.org",
755
+ description: "Spaces around the local part",
756
+ feature: "fws",
757
+ expected: allBut5322(fail("syntax.local.unquoted_space", 0), valid)
758
+ },
759
+ {
760
+ isemail: 86,
761
+ address: "test@ iana .com",
762
+ description: "Spaces around a domain label",
763
+ feature: "fws",
764
+ expected: allBut5322(fail("syntax.domain.invalid_char", 5), valid)
765
+ },
766
+ {
767
+ isemail: 87,
768
+ address: "test . test@iana.org",
769
+ description: "Spaces around a dot in the local part",
770
+ feature: "fws",
771
+ expected: allBut5322(fail("syntax.local.unquoted_space", 4), valid)
772
+ },
773
+ {
774
+ isemail: 88,
775
+ address: "\r\n test@iana.org",
776
+ description: "Folded whitespace before the local part",
777
+ feature: "fws",
778
+ expected: allBut5322(fail("syntax.local.invalid_char", 0), valid)
779
+ },
780
+ {
781
+ isemail: 89,
782
+ address: "\r\n \r\n test@iana.org",
783
+ description: "Whitespace folded twice before the local part",
784
+ feature: "fws",
785
+ expected: allBut5322(fail("syntax.local.invalid_char", 0), valid)
786
+ },
787
+ {
788
+ isemail: 90,
789
+ address: "(comment)test@iana.org",
790
+ description: "Comment before the local part",
791
+ feature: "comments",
792
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 0))
793
+ },
794
+ {
795
+ isemail: 91,
796
+ address: "((comment)test@iana.org",
797
+ description: "Unterminated comment around a nested one",
798
+ expected: allBut5322(fail("syntax.comment.not_allowed", 0), fail("syntax.address.no_at"))
799
+ },
800
+ {
801
+ isemail: 92,
802
+ address: "(comment(comment))test@iana.org",
803
+ description: "Nested comment",
804
+ feature: "comments",
805
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 0))
806
+ },
807
+ {
808
+ isemail: 93,
809
+ address: "test@(comment)iana.org",
810
+ description: "Comment before the domain",
811
+ feature: "comments",
812
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 5))
813
+ },
814
+ {
815
+ isemail: 94,
816
+ address: "test(comment)test@iana.org",
817
+ description: "Comment between two atoms with no dot",
818
+ expected: allBut5322(fail("syntax.comment.not_allowed", 4), fail("syntax.local.invalid_char", 13))
819
+ },
820
+ {
821
+ isemail: 95,
822
+ address: "test@(comment)[255.255.255.255]",
823
+ description: "Comment before a domain literal",
824
+ feature: "comments",
825
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 5))
826
+ },
827
+ {
828
+ isemail: 96,
829
+ address: "(comment)abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@iana.org",
830
+ description: "Comment before a 64-character local part",
831
+ feature: "comments",
832
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 0))
833
+ },
834
+ {
835
+ isemail: 97,
836
+ address: `test@(comment)${longLabel}.com`,
837
+ description: "Comment before a 63-character domain label",
838
+ feature: "comments",
839
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 5))
840
+ },
841
+ {
842
+ isemail: 98,
843
+ address: "(comment)test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghik.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghik.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstu",
844
+ description: "Comment before a 254-character address",
845
+ feature: "comments",
846
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 0))
847
+ },
848
+ {
849
+ isemail: 99,
850
+ address: "test@iana.org\n",
851
+ description: "Trailing line feed",
852
+ expected: everywhere(fail("syntax.domain.invalid_char", 13))
853
+ },
854
+ {
855
+ isemail: 100,
856
+ address: "test@xn--hxajbheg2az3al.xn--jxalpdlp",
857
+ description: "Punycode domain with a retired test TLD",
858
+ feature: "unknown-tld",
859
+ expected: {
860
+ ...everywhere(valid),
861
+ practical: fail("syntax.tld.unknown")
862
+ }
863
+ },
864
+ {
865
+ isemail: 101,
866
+ address: "xn--test@iana.org",
867
+ description: "Punycode prefix in the local part",
868
+ feature: "dot-atom",
869
+ expected: everywhere(valid)
870
+ },
871
+ {
872
+ isemail: 102,
873
+ address: "test@iana.org-",
874
+ description: "TLD ending with a hyphen",
875
+ expected: everywhere(fail("syntax.domain.label_invalid", 13))
876
+ },
877
+ {
878
+ isemail: 104,
879
+ address: "(test@iana.org",
880
+ description: "Unterminated comment before the @",
881
+ expected: allBut5322(fail("syntax.comment.not_allowed", 0), fail("syntax.address.no_at"))
882
+ },
883
+ {
884
+ isemail: 105,
885
+ address: "test@(iana.org",
886
+ description: "Unterminated comment in the domain",
887
+ expected: allBut5322(fail("syntax.comment.not_allowed", 5), fail("syntax.comment.unterminated", 5))
888
+ },
889
+ {
890
+ isemail: 106,
891
+ address: "test@[1.2.3.4",
892
+ description: "Unterminated domain literal",
893
+ expected: {
894
+ practical: fail("syntax.domain.invalid_char", 5),
895
+ rfc5321: fail("syntax.domain.literal_invalid", 5),
896
+ rfc5322: fail("syntax.domain.literal_invalid", 5),
897
+ html5: fail("syntax.domain.invalid_char", 5)
898
+ }
899
+ },
900
+ {
901
+ isemail: 107,
902
+ address: "\"test\\\"@iana.org",
903
+ description: "Quoted string whose closing quote is escaped",
904
+ expected: quotedLocal(fail("syntax.address.no_at"))
905
+ },
906
+ {
907
+ isemail: 108,
908
+ address: "(comment\\)test@iana.org",
909
+ description: "Comment whose closing parenthesis is escaped",
910
+ expected: allBut5322(fail("syntax.comment.not_allowed", 0), fail("syntax.address.no_at"))
911
+ },
912
+ {
913
+ isemail: 109,
914
+ address: "test@iana.org(comment\\)",
915
+ description: "Trailing comment whose closing parenthesis is escaped",
916
+ expected: allBut5322(fail("syntax.comment.not_allowed", 13), fail("syntax.comment.unterminated", 13))
917
+ },
918
+ {
919
+ isemail: 110,
920
+ address: "test@iana.org(comment\\",
921
+ description: "Trailing comment ending in a backslash",
922
+ expected: allBut5322(fail("syntax.comment.not_allowed", 13), fail("syntax.comment.unterminated", 13))
923
+ },
924
+ {
925
+ isemail: 112,
926
+ address: "test@[RFC-5322-domain-literal]",
927
+ description: "Domain literal that isn't an address",
928
+ feature: "general-literal",
929
+ expected: rfc5322Literal
930
+ },
931
+ {
932
+ isemail: 113,
933
+ address: "test@[RFC-5322]-domain-literal]",
934
+ description: "Text after a domain literal",
935
+ expected: {
936
+ ...rfc5322Literal,
937
+ rfc5322: fail("syntax.domain.invalid_char", 15)
938
+ }
939
+ },
940
+ {
941
+ isemail: 114,
942
+ address: "test@[RFC-5322-[domain-literal]",
943
+ description: "Unescaped [ inside a domain literal",
944
+ expected: {
945
+ ...rfc5322Literal,
946
+ rfc5322: fail("syntax.domain.literal_invalid", 5)
947
+ }
948
+ },
949
+ {
950
+ isemail: 115,
951
+ address: "test@[RFC-5322-\\\x07-domain-literal]",
952
+ description: "Escaped BEL in a domain literal",
953
+ feature: "obs-control",
954
+ expected: rfc5322Literal
955
+ },
956
+ {
957
+ isemail: 116,
958
+ address: "test@[RFC-5322-\\ -domain-literal]",
959
+ description: "Escaped tab in a domain literal",
960
+ feature: "general-literal",
961
+ expected: rfc5322Literal
962
+ },
963
+ {
964
+ isemail: 117,
965
+ address: "test@[RFC-5322-\\]-domain-literal]",
966
+ description: "Escaped ] in a domain literal",
967
+ feature: "general-literal",
968
+ expected: rfc5322Literal
969
+ },
970
+ {
971
+ isemail: 118,
972
+ address: "test@[RFC-5322-domain-literal\\]",
973
+ description: "Domain literal whose closing bracket is escaped",
974
+ expected: {
975
+ ...rfc5322Literal,
976
+ rfc5322: fail("syntax.domain.literal_invalid", 5)
977
+ }
978
+ },
979
+ {
980
+ isemail: 119,
981
+ address: "test@[RFC-5322-domain-literal\\",
982
+ description: "Domain literal ending in a backslash",
983
+ expected: {
984
+ ...rfc5322Literal,
985
+ rfc5322: fail("syntax.domain.literal_invalid", 5)
986
+ }
987
+ },
988
+ {
989
+ isemail: 120,
990
+ address: "test@[RFC 5322 domain literal]",
991
+ description: "Spaces in a domain literal",
992
+ feature: "general-literal",
993
+ expected: rfc5322Literal
994
+ },
995
+ {
996
+ isemail: 121,
997
+ address: "test@[RFC-5322-domain-literal] (comment)",
998
+ description: "Comment after a domain literal",
999
+ expected: rfc5322Literal
1000
+ },
1001
+ {
1002
+ isemail: 123,
1003
+ address: "test@.org",
1004
+ description: "Domain starting with a dot before the TLD",
1005
+ expected: everywhere(fail("syntax.domain.label_invalid", 5))
1006
+ },
1007
+ {
1008
+ isemail: 124,
1009
+ address: "\"\"@iana.org",
1010
+ description: "DEL in a quoted string",
1011
+ feature: "obs-control",
1012
+ expected: {
1013
+ ...quotedLocal(valid),
1014
+ rfc5321: fail("syntax.local.invalid_char", 1)
1015
+ }
1016
+ },
1017
+ {
1018
+ isemail: 125,
1019
+ address: "\"\\\"@iana.org",
1020
+ description: "Escaped DEL in a quoted string",
1021
+ feature: "obs-control",
1022
+ expected: {
1023
+ ...quotedLocal(valid),
1024
+ rfc5321: fail("syntax.local.invalid_char", 2)
1025
+ }
1026
+ },
1027
+ {
1028
+ isemail: 126,
1029
+ address: "()test@iana.org",
1030
+ description: "DEL in a comment",
1031
+ feature: "obs-control",
1032
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 0))
1033
+ },
1034
+ {
1035
+ isemail: 127,
1036
+ address: "test@iana.org\r",
1037
+ description: "Trailing CR",
1038
+ expected: everywhere(fail("syntax.domain.invalid_char", 13))
1039
+ },
1040
+ {
1041
+ isemail: 128,
1042
+ address: "\rtest@iana.org",
1043
+ description: "Leading CR",
1044
+ expected: everywhere(fail("syntax.local.invalid_char", 0))
1045
+ },
1046
+ {
1047
+ isemail: 129,
1048
+ address: "\"\rtest\"@iana.org",
1049
+ description: "CR in a quoted string",
1050
+ expected: quotedLocal(fail("syntax.local.invalid_char", 1))
1051
+ },
1052
+ {
1053
+ isemail: 130,
1054
+ address: "(\r)test@iana.org",
1055
+ description: "CR in a comment",
1056
+ expected: allBut5322(fail("syntax.comment.not_allowed", 0), fail("syntax.local.invalid_char", 1))
1057
+ },
1058
+ {
1059
+ isemail: 131,
1060
+ address: "test@iana.org(\r)",
1061
+ description: "CR in a trailing comment",
1062
+ expected: allBut5322(fail("syntax.comment.not_allowed", 13), fail("syntax.domain.invalid_char", 14))
1063
+ },
1064
+ {
1065
+ isemail: 132,
1066
+ address: "\ntest@iana.org",
1067
+ description: "Leading LF",
1068
+ expected: everywhere(fail("syntax.local.invalid_char", 0))
1069
+ },
1070
+ {
1071
+ isemail: 133,
1072
+ address: "\"\n\"@iana.org",
1073
+ description: "LF in a quoted string",
1074
+ expected: quotedLocal(fail("syntax.local.invalid_char", 1))
1075
+ },
1076
+ {
1077
+ isemail: 134,
1078
+ address: "\"\\\n\"@iana.org",
1079
+ description: "Escaped LF in a quoted string",
1080
+ feature: "obs-control",
1081
+ expected: {
1082
+ ...quotedLocal(valid),
1083
+ rfc5321: fail("syntax.local.invalid_char", 2)
1084
+ }
1085
+ },
1086
+ {
1087
+ isemail: 135,
1088
+ address: "(\n)test@iana.org",
1089
+ description: "LF in a comment",
1090
+ expected: allBut5322(fail("syntax.comment.not_allowed", 0), fail("syntax.local.invalid_char", 1))
1091
+ },
1092
+ {
1093
+ isemail: 136,
1094
+ address: "\x07@iana.org",
1095
+ description: "BEL as the local part",
1096
+ expected: everywhere(fail("syntax.local.invalid_char", 0))
1097
+ },
1098
+ {
1099
+ isemail: 137,
1100
+ address: "test@\x07.org",
1101
+ description: "BEL as a domain label",
1102
+ expected: everywhere(fail("syntax.domain.invalid_char", 5))
1103
+ },
1104
+ {
1105
+ isemail: 138,
1106
+ address: "\"\x07\"@iana.org",
1107
+ description: "BEL in a quoted string",
1108
+ feature: "obs-control",
1109
+ expected: {
1110
+ ...quotedLocal(valid),
1111
+ rfc5321: fail("syntax.local.invalid_char", 1)
1112
+ }
1113
+ },
1114
+ {
1115
+ isemail: 139,
1116
+ address: "\"\\\x07\"@iana.org",
1117
+ description: "Escaped BEL in a quoted string",
1118
+ feature: "obs-control",
1119
+ expected: {
1120
+ ...quotedLocal(valid),
1121
+ rfc5321: fail("syntax.local.invalid_char", 2)
1122
+ }
1123
+ },
1124
+ {
1125
+ isemail: 140,
1126
+ address: "(\x07)test@iana.org",
1127
+ description: "BEL in a comment",
1128
+ feature: "obs-control",
1129
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 0))
1130
+ },
1131
+ {
1132
+ isemail: 141,
1133
+ address: "\r\ntest@iana.org",
1134
+ description: "Leading CRLF with no whitespace after it",
1135
+ expected: everywhere(fail("syntax.local.invalid_char", 0))
1136
+ },
1137
+ {
1138
+ isemail: 142,
1139
+ address: "\r\n \r\ntest@iana.org",
1140
+ description: "Folded whitespace ending in a CRLF",
1141
+ expected: allBut5322(fail("syntax.local.invalid_char", 0), fail("syntax.local.invalid_char", 3))
1142
+ },
1143
+ {
1144
+ isemail: 143,
1145
+ address: " \r\ntest@iana.org",
1146
+ description: "Space then a CRLF with no whitespace after it",
1147
+ expected: allBut5322(fail("syntax.local.unquoted_space", 0), fail("syntax.local.invalid_char", 1))
1148
+ },
1149
+ {
1150
+ isemail: 144,
1151
+ address: " \r\n test@iana.org",
1152
+ description: "Folded whitespace before the local part, starting with a space",
1153
+ feature: "fws",
1154
+ expected: allBut5322(fail("syntax.local.unquoted_space", 0), valid)
1155
+ },
1156
+ {
1157
+ isemail: 145,
1158
+ address: " \r\n \r\ntest@iana.org",
1159
+ description: "Folded whitespace ending in a CRLF, starting with a space",
1160
+ expected: allBut5322(fail("syntax.local.unquoted_space", 0), fail("syntax.local.invalid_char", 4))
1161
+ },
1162
+ {
1163
+ isemail: 146,
1164
+ address: " \r\n\r\ntest@iana.org",
1165
+ description: "Two CRLFs in a row",
1166
+ expected: allBut5322(fail("syntax.local.unquoted_space", 0), fail("syntax.local.invalid_char", 1))
1167
+ },
1168
+ {
1169
+ isemail: 147,
1170
+ address: " \r\n\r\n test@iana.org",
1171
+ description: "Two CRLFs in a row, then a space",
1172
+ expected: allBut5322(fail("syntax.local.unquoted_space", 0), fail("syntax.local.invalid_char", 1))
1173
+ },
1174
+ {
1175
+ isemail: 148,
1176
+ address: "test@iana.org\r\n ",
1177
+ description: "Folded whitespace after the domain",
1178
+ feature: "fws",
1179
+ expected: allBut5322(fail("syntax.domain.invalid_char", 13), valid)
1180
+ },
1181
+ {
1182
+ isemail: 149,
1183
+ address: "test@iana.org\r\n \r\n ",
1184
+ description: "Whitespace folded twice after the domain",
1185
+ feature: "fws",
1186
+ expected: allBut5322(fail("syntax.domain.invalid_char", 13), valid)
1187
+ },
1188
+ {
1189
+ isemail: 150,
1190
+ address: "test@iana.org\r\n",
1191
+ description: "Trailing CRLF",
1192
+ expected: everywhere(fail("syntax.domain.invalid_char", 13))
1193
+ },
1194
+ {
1195
+ isemail: 151,
1196
+ address: "test@iana.org\r\n \r\n",
1197
+ description: "Folded whitespace after the domain, ending in a CRLF",
1198
+ expected: allBut5322(fail("syntax.domain.invalid_char", 13), fail("syntax.domain.invalid_char", 16))
1199
+ },
1200
+ {
1201
+ isemail: 152,
1202
+ address: "test@iana.org \r\n",
1203
+ description: "Trailing space then a CRLF",
1204
+ expected: allBut5322(fail("syntax.domain.invalid_char", 13), fail("syntax.domain.invalid_char", 14))
1205
+ },
1206
+ {
1207
+ isemail: 153,
1208
+ address: "test@iana.org \r\n ",
1209
+ description: "Folded whitespace after the domain, starting with a space",
1210
+ feature: "fws",
1211
+ expected: allBut5322(fail("syntax.domain.invalid_char", 13), valid)
1212
+ },
1213
+ {
1214
+ isemail: 154,
1215
+ address: "test@iana.org \r\n \r\n",
1216
+ description: "Folded whitespace after the domain, starting with a space and ending in a CRLF",
1217
+ expected: allBut5322(fail("syntax.domain.invalid_char", 13), fail("syntax.domain.invalid_char", 17))
1218
+ },
1219
+ {
1220
+ isemail: 155,
1221
+ address: "test@iana.org \r\n\r\n",
1222
+ description: "Trailing space then two CRLFs",
1223
+ expected: allBut5322(fail("syntax.domain.invalid_char", 13), fail("syntax.domain.invalid_char", 14))
1224
+ },
1225
+ {
1226
+ isemail: 156,
1227
+ address: "test@iana.org \r\n\r\n ",
1228
+ description: "Trailing space then two CRLFs and a space",
1229
+ expected: allBut5322(fail("syntax.domain.invalid_char", 13), fail("syntax.domain.invalid_char", 14))
1230
+ },
1231
+ {
1232
+ isemail: 157,
1233
+ address: " test@iana.org",
1234
+ description: "Leading space",
1235
+ feature: "fws",
1236
+ expected: allBut5322(fail("syntax.local.unquoted_space", 0), valid)
1237
+ },
1238
+ {
1239
+ isemail: 158,
1240
+ address: "test@iana.org ",
1241
+ description: "Trailing space",
1242
+ feature: "fws",
1243
+ expected: allBut5322(fail("syntax.domain.invalid_char", 13), valid)
1244
+ },
1245
+ {
1246
+ isemail: 159,
1247
+ address: "test@[IPv6:1::2:]",
1248
+ description: "IPv6 literal ending with a single colon",
1249
+ feature: "general-literal",
1250
+ expected: rfc5322Literal
1251
+ },
1252
+ {
1253
+ isemail: 160,
1254
+ address: "\"test\\©\"@iana.org",
1255
+ description: "Escaped non-ASCII character in a quoted string",
1256
+ expected: quotedLocal(fail("syntax.local.invalid_char", 6))
1257
+ },
1258
+ {
1259
+ isemail: 161,
1260
+ address: "test@iana/icann.org",
1261
+ description: "Slash in the domain",
1262
+ expected: allBut5322(fail("syntax.domain.invalid_char", 9), valid)
1263
+ },
1264
+ {
1265
+ isemail: 165,
1266
+ address: "test.(comment)test@iana.org",
1267
+ description: "Comment after a dot in the local part",
1268
+ feature: "comments",
1269
+ expected: rfc5322Only(fail("syntax.comment.not_allowed", 5))
1270
+ },
1271
+ {
1272
+ isemail: 166,
1273
+ address: "test@org",
1274
+ description: "TLD alone as the domain",
1275
+ feature: "dotless-domain",
1276
+ expected: {
1277
+ ...everywhere(fail("syntax.domain.no_dot")),
1278
+ html5: valid
1279
+ }
1280
+ },
1281
+ {
1282
+ isemail: 167,
1283
+ address: "test@test.com",
1284
+ description: "Common test domain",
1285
+ feature: "dot-atom",
1286
+ expected: everywhere(valid)
1287
+ },
1288
+ {
1289
+ isemail: 168,
1290
+ address: "test@nic.no",
1291
+ description: "Country-code TLD",
1292
+ feature: "dot-atom",
1293
+ expected: everywhere(valid)
1294
+ }
1295
+ ];
1296
+ //#endregion
1297
+ //#region src/fixtures/legacy.ts
1298
+ const quotedLocalRejected = "practical rejects quoted local parts, which are legal but never seen on real mailboxes";
1299
+ const routeRejected = "practical rejects `%` and `!`, the source-route and bang-path characters, which are legal but never seen on real mailboxes";
1300
+ /** The 0.0.1 suite reran these cases uppercased, under `local.alphaLower: false`. */
1301
+ function withUppercase(fixture) {
1302
+ return [fixture, {
1303
+ ...fixture,
1304
+ address: fixture.address.toUpperCase(),
1305
+ description: `${fixture.description}, uppercased`
1306
+ }];
1307
+ }
1308
+ const legacyFixtures = [
1309
+ ...withUppercase({
1310
+ address: "simple@example.com",
1311
+ description: "Simple address",
1312
+ feature: "dot-atom",
1313
+ expected: everywhere(valid),
1314
+ legacy: true
1315
+ }),
1316
+ ...withUppercase({
1317
+ address: "x@example.com",
1318
+ description: "Single-letter local part",
1319
+ feature: "dot-atom",
1320
+ expected: everywhere(valid),
1321
+ legacy: true
1322
+ }),
1323
+ ...withUppercase({
1324
+ address: "admin@test.co",
1325
+ description: "Two-letter TLD",
1326
+ feature: "dot-atom",
1327
+ expected: everywhere(valid),
1328
+ legacy: true
1329
+ }),
1330
+ ...withUppercase({
1331
+ address: "test@gmail.com",
1332
+ description: "Gmail address",
1333
+ feature: "dot-atom",
1334
+ expected: everywhere(valid),
1335
+ legacy: true
1336
+ }),
1337
+ ...withUppercase({
1338
+ address: "tesT@example.com",
1339
+ description: "Uppercase letter in the local part",
1340
+ feature: "dot-atom",
1341
+ expected: everywhere(valid),
1342
+ legacy: true
1343
+ }),
1344
+ ...withUppercase({
1345
+ address: "test1@example.com",
1346
+ description: "Digit in the local part",
1347
+ feature: "dot-atom",
1348
+ expected: everywhere(valid),
1349
+ legacy: true
1350
+ }),
1351
+ {
1352
+ address: "simple1@example.com",
1353
+ description: "Digit at the end of the local part",
1354
+ feature: "dot-atom",
1355
+ expected: everywhere(valid),
1356
+ legacy: true
1357
+ },
1358
+ ...withUppercase({
1359
+ address: "very.common@example.com",
1360
+ description: "Dot in the local part",
1361
+ feature: "dot-atom",
1362
+ expected: everywhere(valid),
1363
+ legacy: true
1364
+ }),
1365
+ {
1366
+ address: "disposable.style.email.with+symbol@example.com",
1367
+ description: "Dots and a plus sign in the local part",
1368
+ feature: "atext-specials",
1369
+ expected: everywhere(valid),
1370
+ legacy: true
1371
+ },
1372
+ {
1373
+ address: "other.email-with-hyphen@example.com",
1374
+ description: "Dots and hyphens in the local part",
1375
+ feature: "atext-specials",
1376
+ expected: everywhere(valid),
1377
+ legacy: true
1378
+ },
1379
+ {
1380
+ address: "user.name+tag+sorting@example.com",
1381
+ description: "Dot and plus-sign tags in the local part",
1382
+ feature: "atext-specials",
1383
+ expected: everywhere(valid),
1384
+ legacy: true
1385
+ },
1386
+ ...withUppercase({
1387
+ address: "disposablestyleemailwith+symbol@example.com",
1388
+ description: "Plus sign in the local part",
1389
+ feature: "atext-specials",
1390
+ expected: everywhere(valid),
1391
+ legacy: true
1392
+ }),
1393
+ ...withUppercase({
1394
+ address: "username+tag+sorting@example.com",
1395
+ description: "Plus-sign tags in the local part",
1396
+ feature: "atext-specials",
1397
+ expected: everywhere(valid),
1398
+ legacy: true
1399
+ }),
1400
+ ...withUppercase({
1401
+ address: "test/test@test.com",
1402
+ description: "Slash in the local part",
1403
+ feature: "atext-specials",
1404
+ expected: everywhere(valid),
1405
+ legacy: true
1406
+ }),
1407
+ ...withUppercase({
1408
+ address: "mailhost.com!username@example.org",
1409
+ description: "Bang path in the local part, dotted relay host",
1410
+ feature: "route-chars",
1411
+ expected: {
1412
+ ...everywhere(valid),
1413
+ practical: fail("syntax.local.invalid_char", 12)
1414
+ },
1415
+ legacy: true,
1416
+ flipped: routeRejected
1417
+ }),
1418
+ {
1419
+ address: "mailhost!username@example.org",
1420
+ description: "Bang path in the local part, dotless relay host",
1421
+ feature: "route-chars",
1422
+ expected: {
1423
+ ...everywhere(valid),
1424
+ practical: fail("syntax.local.invalid_char", 8)
1425
+ },
1426
+ legacy: false
1427
+ },
1428
+ ...withUppercase({
1429
+ address: "user%example.com@example.org",
1430
+ description: "Percent route in the local part, dotted relay host",
1431
+ feature: "route-chars",
1432
+ expected: {
1433
+ ...everywhere(valid),
1434
+ practical: fail("syntax.local.invalid_char", 4)
1435
+ },
1436
+ legacy: true,
1437
+ flipped: routeRejected
1438
+ }),
1439
+ {
1440
+ address: "user%example@example.org",
1441
+ description: "Percent route in the local part, dotless relay host",
1442
+ feature: "route-chars",
1443
+ expected: {
1444
+ ...everywhere(valid),
1445
+ practical: fail("syntax.local.invalid_char", 4)
1446
+ },
1447
+ legacy: false
1448
+ },
1449
+ ...withUppercase({
1450
+ address: "fully-qualified-domain@example.com",
1451
+ description: "Hyphens in the local part",
1452
+ feature: "atext-specials",
1453
+ expected: everywhere(valid),
1454
+ legacy: true
1455
+ }),
1456
+ ...withUppercase({
1457
+ address: "otheremail-with-hyphen@example.com",
1458
+ description: "Hyphens in the local part",
1459
+ feature: "atext-specials",
1460
+ expected: everywhere(valid),
1461
+ legacy: true
1462
+ }),
1463
+ ...withUppercase({
1464
+ address: "user-@example.org",
1465
+ description: "Local part ending in a hyphen",
1466
+ feature: "atext-specials",
1467
+ expected: everywhere(valid),
1468
+ legacy: true
1469
+ }),
1470
+ ...withUppercase({
1471
+ address: "exampleindeed@strange-example.com",
1472
+ description: "Hyphenated domain",
1473
+ feature: "dot-atom",
1474
+ expected: everywhere(valid),
1475
+ legacy: true
1476
+ }),
1477
+ ...withUppercase({
1478
+ address: "example-indeed@strange-example.com",
1479
+ description: "Hyphens in the local part and the domain",
1480
+ feature: "atext-specials",
1481
+ expected: everywhere(valid),
1482
+ legacy: true
1483
+ }),
1484
+ ...withUppercase({
1485
+ address: "\" \"@example.org",
1486
+ description: "Quoted space as the whole local part",
1487
+ feature: "quoted-local",
1488
+ expected: {
1489
+ practical: fail("syntax.local.invalid_char", 0),
1490
+ rfc5321: valid,
1491
+ rfc5322: valid,
1492
+ html5: fail("syntax.local.invalid_char", 0)
1493
+ },
1494
+ legacy: true,
1495
+ flipped: quotedLocalRejected
1496
+ }),
1497
+ ...withUppercase({
1498
+ address: "\"john..doe\"@example.com",
1499
+ description: "Consecutive dots inside a quoted local part",
1500
+ feature: "quoted-local",
1501
+ expected: {
1502
+ practical: fail("syntax.local.invalid_char", 0),
1503
+ rfc5321: valid,
1504
+ rfc5322: valid,
1505
+ html5: fail("syntax.local.invalid_char", 0)
1506
+ },
1507
+ legacy: true,
1508
+ flipped: quotedLocalRejected
1509
+ }),
1510
+ ...withUppercase({
1511
+ address: "\"justactually\"@example.com",
1512
+ description: "Quoted local part",
1513
+ feature: "quoted-local",
1514
+ expected: {
1515
+ practical: fail("syntax.local.invalid_char", 0),
1516
+ rfc5321: valid,
1517
+ rfc5322: valid,
1518
+ html5: fail("syntax.local.invalid_char", 0)
1519
+ },
1520
+ legacy: true,
1521
+ flipped: quotedLocalRejected
1522
+ }),
1523
+ ...withUppercase({
1524
+ address: "just.\"actually\".right@example.com",
1525
+ description: "Quoted string between dot-separated atoms",
1526
+ feature: "obs-local",
1527
+ expected: {
1528
+ practical: fail("syntax.local.invalid_char", 5),
1529
+ rfc5321: fail("syntax.local.invalid_char", 5),
1530
+ rfc5322: valid,
1531
+ html5: fail("syntax.local.invalid_char", 5)
1532
+ },
1533
+ legacy: true,
1534
+ flipped: quotedLocalRejected
1535
+ }),
1536
+ {
1537
+ address: "just.\"not\".right@example.com",
1538
+ description: "Quoted string between dot-separated atoms",
1539
+ feature: "obs-local",
1540
+ expected: {
1541
+ practical: fail("syntax.local.invalid_char", 5),
1542
+ rfc5321: fail("syntax.local.invalid_char", 5),
1543
+ rfc5322: valid,
1544
+ html5: fail("syntax.local.invalid_char", 5)
1545
+ },
1546
+ legacy: true,
1547
+ flipped: quotedLocalRejected
1548
+ },
1549
+ {
1550
+ address: "\"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual\"@strange.example.com",
1551
+ description: "Quoted strings with specials, missing their escapes",
1552
+ expected: {
1553
+ practical: fail("syntax.local.invalid_char", 0),
1554
+ rfc5321: fail("syntax.local.invalid_char", 16),
1555
+ rfc5322: fail("syntax.local.invalid_char", 31),
1556
+ html5: fail("syntax.local.invalid_char", 0)
1557
+ },
1558
+ legacy: false
1559
+ },
1560
+ ...withUppercase({
1561
+ address: "just\"not\"right@example.com",
1562
+ description: "Quotes inside an atom",
1563
+ expected: everywhere(fail("syntax.local.invalid_char", 4)),
1564
+ legacy: false
1565
+ }),
1566
+ ...withUppercase({
1567
+ address: "just.\"not\"right@example.com",
1568
+ description: "Quoted string with no dot after it",
1569
+ expected: {
1570
+ practical: fail("syntax.local.invalid_char", 5),
1571
+ rfc5321: fail("syntax.local.invalid_char", 5),
1572
+ rfc5322: fail("syntax.local.invalid_char", 10),
1573
+ html5: fail("syntax.local.invalid_char", 5)
1574
+ },
1575
+ legacy: false
1576
+ }),
1577
+ ...withUppercase({
1578
+ address: "just.\"not.\"right@example.com",
1579
+ description: "Quoted string ending in a dot, with no dot after it",
1580
+ expected: {
1581
+ practical: fail("syntax.local.invalid_char", 5),
1582
+ rfc5321: fail("syntax.local.invalid_char", 5),
1583
+ rfc5322: fail("syntax.local.invalid_char", 11),
1584
+ html5: fail("syntax.local.invalid_char", 5)
1585
+ },
1586
+ legacy: false
1587
+ }),
1588
+ ...withUppercase({
1589
+ address: "\"john..doe@example.com",
1590
+ description: "Unterminated quote",
1591
+ expected: {
1592
+ practical: fail("syntax.local.invalid_char", 0),
1593
+ rfc5321: fail("syntax.address.no_at"),
1594
+ rfc5322: fail("syntax.address.no_at"),
1595
+ html5: fail("syntax.local.invalid_char", 0)
1596
+ },
1597
+ legacy: false
1598
+ }),
1599
+ ...withUppercase({
1600
+ address: "\"john\"..doe@example.com",
1601
+ description: "Consecutive dots after a quoted string",
1602
+ expected: {
1603
+ practical: fail("syntax.local.invalid_char", 0),
1604
+ rfc5321: fail("syntax.local.invalid_char", 6),
1605
+ rfc5322: fail("syntax.local.consecutive_dots", 7),
1606
+ html5: fail("syntax.local.invalid_char", 0)
1607
+ },
1608
+ legacy: false
1609
+ }),
1610
+ ...withUppercase({
1611
+ address: "a\"b(c)d,e:f;g<h>i[j\\k]l@example.com",
1612
+ description: "Unquoted specials",
1613
+ expected: everywhere(fail("syntax.local.invalid_char", 1)),
1614
+ legacy: false
1615
+ }),
1616
+ ...withUppercase({
1617
+ address: "james richards@google.com",
1618
+ description: "Unquoted space",
1619
+ expected: everywhere(fail("syntax.local.unquoted_space", 5)),
1620
+ legacy: false
1621
+ }),
1622
+ ...withUppercase({
1623
+ address: "james\" richards@google.com",
1624
+ description: "Space after a stray quote",
1625
+ expected: everywhere(fail("syntax.local.invalid_char", 5)),
1626
+ legacy: false
1627
+ }),
1628
+ ...withUppercase({
1629
+ address: "this is\"notallowed@example.com",
1630
+ description: "Unquoted space and a stray quote",
1631
+ expected: everywhere(fail("syntax.local.unquoted_space", 4)),
1632
+ legacy: false
1633
+ }),
1634
+ ...withUppercase({
1635
+ address: "this still\"not\\allowed@example.com",
1636
+ description: "Unquoted space, a stray quote, and a backslash",
1637
+ expected: everywhere(fail("syntax.local.unquoted_space", 4)),
1638
+ legacy: false
1639
+ }),
1640
+ ...withUppercase({
1641
+ address: "john..doe@example.com",
1642
+ description: "Consecutive dots in the local part",
1643
+ feature: "misplaced-dots",
1644
+ expected: {
1645
+ practical: fail("syntax.local.consecutive_dots", 5),
1646
+ rfc5321: fail("syntax.local.consecutive_dots", 5),
1647
+ rfc5322: fail("syntax.local.consecutive_dots", 5),
1648
+ html5: valid
1649
+ },
1650
+ legacy: false
1651
+ }),
1652
+ ...withUppercase({
1653
+ address: "john.doe@example..com",
1654
+ description: "Consecutive dots in the domain",
1655
+ expected: everywhere(fail("syntax.domain.label_invalid", 17)),
1656
+ legacy: false
1657
+ }),
1658
+ ...withUppercase({
1659
+ address: "Abc.example.com",
1660
+ description: "No @",
1661
+ expected: everywhere(fail("syntax.address.no_at")),
1662
+ legacy: false
1663
+ }),
1664
+ {
1665
+ address: "Abc+example.com",
1666
+ description: "No @",
1667
+ expected: everywhere(fail("syntax.address.no_at")),
1668
+ legacy: false
1669
+ },
1670
+ ...withUppercase({
1671
+ address: "@Abc.example.com",
1672
+ description: "Nothing before the @",
1673
+ expected: everywhere(fail("syntax.local.empty")),
1674
+ legacy: false
1675
+ }),
1676
+ ...withUppercase({
1677
+ address: "A@b@c@example.com",
1678
+ description: "More than one @",
1679
+ expected: everywhere(fail("syntax.local.invalid_char", 1)),
1680
+ legacy: false
1681
+ }),
1682
+ ...withUppercase({
1683
+ address: "QA☕CHOCOLATE☕@test.com",
1684
+ description: "Non-ASCII characters in the local part",
1685
+ expected: everywhere(fail("syntax.local.invalid_char", 2)),
1686
+ legacy: false
1687
+ }),
1688
+ ...withUppercase({
1689
+ address: "i_like_underscore@but_its_not_allowed_in_this_part.example.com",
1690
+ description: "Underscores in the domain",
1691
+ expected: allBut5322(fail("syntax.domain.invalid_char", 21), valid),
1692
+ legacy: false
1693
+ }),
1694
+ ...withUppercase({
1695
+ address: "james@cb$.com",
1696
+ description: "Dollar sign in the domain",
1697
+ expected: allBut5322(fail("syntax.domain.invalid_char", 8), valid),
1698
+ legacy: false
1699
+ }),
1700
+ ...withUppercase({
1701
+ address: "1234567890123456789012345678901234567890123456789012345678901234+x@example.com",
1702
+ description: "Local part over 64 characters",
1703
+ feature: "long-local",
1704
+ expected: {
1705
+ practical: fail("syntax.local.too_long"),
1706
+ rfc5321: fail("syntax.local.too_long"),
1707
+ rfc5322: valid,
1708
+ html5: valid
1709
+ },
1710
+ legacy: false
1711
+ }),
1712
+ {
1713
+ address: "uayuYfBgRktoqVPCAJLhkcyVHFsZygReesttpNWTTiETtbQFfDUMZjyCdeaEhcotf+x@example.com",
1714
+ description: "Local part over 64 characters, letters only",
1715
+ feature: "long-local",
1716
+ expected: {
1717
+ practical: fail("syntax.local.too_long"),
1718
+ rfc5321: fail("syntax.local.too_long"),
1719
+ rfc5322: valid,
1720
+ html5: valid
1721
+ },
1722
+ legacy: false
1723
+ },
1724
+ ...withUppercase({
1725
+ address: "james@google",
1726
+ description: "Domain with no dot",
1727
+ feature: "dotless-domain",
1728
+ expected: {
1729
+ practical: fail("syntax.domain.no_dot"),
1730
+ rfc5321: fail("syntax.domain.no_dot"),
1731
+ rfc5322: fail("syntax.domain.no_dot"),
1732
+ html5: valid
1733
+ },
1734
+ legacy: false
1735
+ }),
1736
+ {
1737
+ address: "admin@mailserver1",
1738
+ description: "Domain with no dot, ending in a digit",
1739
+ feature: "dotless-domain",
1740
+ expected: {
1741
+ practical: fail("syntax.domain.no_dot"),
1742
+ rfc5321: fail("syntax.domain.no_dot"),
1743
+ rfc5322: fail("syntax.domain.no_dot"),
1744
+ html5: valid
1745
+ },
1746
+ legacy: false
1747
+ },
1748
+ {
1749
+ address: "james@g.com",
1750
+ description: "Single-character domain label",
1751
+ feature: "dot-atom",
1752
+ expected: everywhere(valid),
1753
+ legacy: false,
1754
+ flipped: "0.0.1 required two characters before the last dot (`charsBeforeDot`), rejecting real single-letter domains (validator-syntax#12)"
1755
+ },
1756
+ {
1757
+ address: "james@google.c",
1758
+ description: "Single-character TLD",
1759
+ feature: "unknown-tld",
1760
+ expected: {
1761
+ practical: fail("syntax.tld.unknown"),
1762
+ rfc5321: valid,
1763
+ rfc5322: valid,
1764
+ html5: valid
1765
+ },
1766
+ legacy: false
1767
+ },
1768
+ {
1769
+ address: "test@example.thisisnotavalidtld",
1770
+ description: "TLD outside the IANA set",
1771
+ feature: "unknown-tld",
1772
+ expected: {
1773
+ practical: fail("syntax.tld.unknown"),
1774
+ rfc5321: valid,
1775
+ rfc5322: valid,
1776
+ html5: valid
1777
+ },
1778
+ legacy: false
1779
+ }
1780
+ ];
1781
+ //#endregion
1782
+ //#region src/fixtures/rfc3696.ts
1783
+ const rfc3696Fixtures = [
1784
+ {
1785
+ address: "Abc\\@def@example.com",
1786
+ description: "Backslash-escaped @ outside a quoted string",
1787
+ expected: everywhere(fail("syntax.local.invalid_char", 3))
1788
+ },
1789
+ {
1790
+ address: "Fred\\ Bloggs@example.com",
1791
+ description: "Backslash-escaped space outside a quoted string",
1792
+ expected: everywhere(fail("syntax.local.invalid_char", 4))
1793
+ },
1794
+ {
1795
+ address: "Joe.\\\\Blow@example.com",
1796
+ description: "Backslash-escaped backslash outside a quoted string",
1797
+ expected: everywhere(fail("syntax.local.invalid_char", 4))
1798
+ },
1799
+ {
1800
+ address: "\"Abc\\@def\"@example.com",
1801
+ description: "Escaped @ in a quoted string",
1802
+ feature: "quoted-pair",
1803
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
1804
+ },
1805
+ {
1806
+ address: "\"Fred\\ Bloggs\"@example.com",
1807
+ description: "Escaped space in a quoted string",
1808
+ feature: "quoted-pair",
1809
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
1810
+ },
1811
+ {
1812
+ address: "\"Joe.\\\\Blow\"@example.com",
1813
+ description: "Escaped backslash in a quoted string",
1814
+ feature: "quoted-pair",
1815
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
1816
+ },
1817
+ {
1818
+ address: "\"Abc@def\"@example.com",
1819
+ description: "Quoted @",
1820
+ feature: "quoted-local",
1821
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
1822
+ },
1823
+ {
1824
+ address: "\"Fred Bloggs\"@example.com",
1825
+ description: "Quoted space",
1826
+ feature: "quoted-local",
1827
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
1828
+ },
1829
+ {
1830
+ address: "user+mailbox@example.com",
1831
+ description: "Plus sign",
1832
+ feature: "atext-specials",
1833
+ expected: everywhere(valid)
1834
+ },
1835
+ {
1836
+ address: "customer/department=shipping@example.com",
1837
+ description: "Slash and equals sign",
1838
+ feature: "atext-specials",
1839
+ expected: everywhere(valid)
1840
+ },
1841
+ {
1842
+ address: "$A12345@example.com",
1843
+ description: "Dollar sign first",
1844
+ feature: "atext-specials",
1845
+ expected: everywhere(valid)
1846
+ },
1847
+ {
1848
+ address: "!def!xyz%abc@example.com",
1849
+ description: "Bang path and percent route",
1850
+ feature: "route-chars",
1851
+ expected: {
1852
+ ...everywhere(valid),
1853
+ practical: fail("syntax.local.invalid_char", 0)
1854
+ }
1855
+ },
1856
+ {
1857
+ address: "_somename@example.com",
1858
+ description: "Underscore first",
1859
+ feature: "atext-specials",
1860
+ expected: everywhere(valid)
1861
+ }
1862
+ ];
1863
+ //#endregion
1864
+ //#region src/fixtures/wikipedia.ts
1865
+ const wikipediaFixtures = [
1866
+ {
1867
+ address: "FirstName.LastName@EasierReading.org",
1868
+ description: "Mixed case",
1869
+ feature: "dot-atom",
1870
+ expected: everywhere(valid)
1871
+ },
1872
+ {
1873
+ address: "long.email-address-with-hyphens@and.subdomains.example.com",
1874
+ description: "Hyphens in the local part, subdomains",
1875
+ feature: "atext-specials",
1876
+ expected: everywhere(valid)
1877
+ },
1878
+ {
1879
+ address: "name/surname@example.com",
1880
+ description: "Slash in the local part",
1881
+ feature: "atext-specials",
1882
+ expected: everywhere(valid)
1883
+ },
1884
+ {
1885
+ address: "admin@example",
1886
+ description: "Domain with no dot",
1887
+ feature: "dotless-domain",
1888
+ expected: {
1889
+ ...everywhere(fail("syntax.domain.no_dot")),
1890
+ html5: valid
1891
+ }
1892
+ },
1893
+ {
1894
+ address: "example@s.example",
1895
+ description: "Reserved TLD",
1896
+ feature: "unknown-tld",
1897
+ expected: {
1898
+ ...everywhere(valid),
1899
+ practical: fail("syntax.tld.unknown")
1900
+ }
1901
+ },
1902
+ {
1903
+ address: "\"jane..doe\"@example.org",
1904
+ description: "Consecutive dots inside a quoted local part",
1905
+ feature: "quoted-local",
1906
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
1907
+ },
1908
+ {
1909
+ address: "\"very.(),:;<>[]\\\".VERY.\\\"very@\\\\ \\\"very\\\".unusual\"@strange.example.com",
1910
+ description: "Quoted string with specials, an @, and escapes",
1911
+ feature: "quoted-pair",
1912
+ expected: rfcOnly(fail("syntax.local.invalid_char", 0))
1913
+ },
1914
+ {
1915
+ address: "postmaster@[123.123.123.123]",
1916
+ description: "IPv4 address literal",
1917
+ feature: "ipv4-literal",
1918
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 11))
1919
+ },
1920
+ {
1921
+ address: "postmaster@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334]",
1922
+ description: "IPv6 address literal",
1923
+ feature: "ipv6-literal",
1924
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 11))
1925
+ },
1926
+ {
1927
+ address: "_test@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334]",
1928
+ description: "Underscore first, IPv6 address literal",
1929
+ feature: "ipv6-literal",
1930
+ expected: rfcOnly(fail("syntax.domain.invalid_char", 6))
1931
+ },
1932
+ {
1933
+ address: "I❤️CHOCOLATE@example.com",
1934
+ description: "Emoji in the local part",
1935
+ expected: everywhere(fail("syntax.local.invalid_char", 1))
1936
+ },
1937
+ {
1938
+ address: "abc.example.com",
1939
+ description: "No @",
1940
+ expected: everywhere(fail("syntax.address.no_at"))
1941
+ },
1942
+ {
1943
+ address: "a@b@c@example.com",
1944
+ description: "More than one @",
1945
+ expected: everywhere(fail("syntax.local.invalid_char", 1))
1946
+ },
1947
+ {
1948
+ address: "this is\"not\\allowed@example.com",
1949
+ description: "Unquoted space, quote, and backslash",
1950
+ expected: everywhere(fail("syntax.local.unquoted_space", 4))
1951
+ },
1952
+ {
1953
+ address: "this\\ still\\\"not\\\\allowed@example.com",
1954
+ description: "Backslash escapes outside a quoted string",
1955
+ expected: everywhere(fail("syntax.local.invalid_char", 4))
1956
+ },
1957
+ {
1958
+ address: "i.like.underscores@but_they_are_not_allowed_in_this_part",
1959
+ description: "Underscores in a dotless domain",
1960
+ expected: allBut5322(fail("syntax.domain.invalid_char", 22), fail("syntax.domain.no_dot"))
1961
+ }
1962
+ ];
1963
+ //#endregion
1964
+ //#region src/fixtures/index.ts
1965
+ /**
1966
+ * The syntax corpus, published as `@email-utils/validator-syntax/fixtures`
1967
+ * so dependents can check they split and judge addresses exactly as
1968
+ * `parseAddress` does, and so the docs can build the support matrix.
1969
+ *
1970
+ * @remarks
1971
+ * Every fixture's `expected` is the result under each preset's default
1972
+ * options. The rules behind them:
1973
+ *
1974
+ * - `practical`: a dot-atom local part (letters, digits, and
1975
+ * ``#$&'*+/=?^_`{|}~-`` with single inner dots), so no quoted strings, no
1976
+ * `%` or `!` routes, and no comments or whitespace; hostname labels with at
1977
+ * least one dot, and no domain literals; the TLD in the IANA set.
1978
+ * - `rfc5321`: an RFC 5321 Dot-string or Quoted-string local part, never
1979
+ * both mixed, capped at 64 characters; hostname labels with at least one
1980
+ * dot, or an IPv4 or `IPv6:` address literal (IPv6 is the only registered
1981
+ * tag, and no more than six groups may sit beside a `::`); no comments or
1982
+ * whitespace.
1983
+ * - `rfc5322`: RFC 5322's addr-spec with its obsolete syntax: dot-separated
1984
+ * atoms and quoted strings mixed, comments and folding whitespace around
1985
+ * every word and label, control characters in quoted strings, comments,
1986
+ * and escapes, and any dtext in a domain literal. Domain labels are
1987
+ * atext, since RFC 5322's domain is a dot-atom, with the hostname rules
1988
+ * for hyphens and length on top. A CRLF must be followed by a space or
1989
+ * tab. No 64-character local cap, but a dotted domain is still required.
1990
+ * - `html5`: exactly the WHATWG `input[type=email]` regex.
1991
+ *
1992
+ * Every preset caps a domain label at 63 characters and the address at 254;
1993
+ * all but `html5` cap the domain at 253. Comments and folding whitespace
1994
+ * don't count toward the caps.
1995
+ *
1996
+ * The address splits on the last `@` outside a quoted string, comment, or
1997
+ * domain literal (validator-syntax#9). A quote opens a quoted string only at
1998
+ * the start of a word; anywhere else it's an invalid character. A quoted
1999
+ * string, comment, or literal left open runs to the end, taking any `@`
2000
+ * with it.
2001
+ *
2002
+ * The first failure wins, checked in this order: empty input; the split;
2003
+ * the local part, left to right, then its length; the domain, left to right,
2004
+ * then its length; the address length; a dotless domain; the TLD. Where a
2005
+ * failure has a position, `index` points at the first offending character
2006
+ * in the whole address: the `(` of a disallowed or unterminated comment,
2007
+ * the `[` of a bad domain literal, the start of an overlong label, and the
2008
+ * CR of a CRLF that isn't followed by whitespace.
2009
+ *
2010
+ * @packageDocumentation
2011
+ */
2012
+ /** Every fixture from every source, each address once. */
2013
+ const syntaxFixtures = [
2014
+ ...legacyFixtures,
2015
+ ...isemailFixtures,
2016
+ ...wikipediaFixtures,
2017
+ ...rfc3696Fixtures
2018
+ ];
2019
+ /** The docs' support matrix: one row per feature, one column per preset. */
2020
+ function supportMatrix() {
2021
+ return syntaxFeatures.map(({ feature, label }) => {
2022
+ const fixtures = syntaxFixtures.filter((fixture) => fixture.feature === feature);
2023
+ const supportIn = (preset) => {
2024
+ const accepted = fixtures.filter((fixture) => fixture.expected[preset].ok).length;
2025
+ if (accepted === fixtures.length) return "yes";
2026
+ return accepted === 0 ? "no" : "partial";
2027
+ };
2028
+ return {
2029
+ feature,
2030
+ label,
2031
+ support: {
2032
+ practical: supportIn("practical"),
2033
+ rfc5321: supportIn("rfc5321"),
2034
+ rfc5322: supportIn("rfc5322"),
2035
+ html5: supportIn("html5")
2036
+ },
2037
+ fixtures
2038
+ };
2039
+ });
2040
+ }
2041
+ /**
2042
+ * Runs `addresses` through `createSyntaxValidator(options)` and splits them
2043
+ * into the ones it accepts and the ones it rejects, each list in input
2044
+ * order.
2045
+ *
2046
+ * @remarks
2047
+ * `changed` marks the addresses the overrides move: those the preset alone
2048
+ * would judge the other way. With no overrides, nothing is changed.
2049
+ *
2050
+ * @example
2051
+ * ```ts
2052
+ * const { valid, invalid } = previewSyntaxOptions({ checkTld: false });
2053
+ * valid.filter((entry) => entry.changed); // now accepted, e.g. example@s.example
2054
+ * previewSyntaxOptions({ preset: 'html5' }, ['ada@localhost']).valid; // [{ address: 'ada@localhost', changed: false }]
2055
+ * ```
2056
+ *
2057
+ * @param addresses - The addresses to judge; `syntaxFixtures` by default.
2058
+ * @throws TypeError when `options` are malformed, or `addresses` isn't an
2059
+ * array of strings.
2060
+ */
2061
+ function previewSyntaxOptions(options, addresses) {
2062
+ const validator = createSyntaxValidator(options);
2063
+ const preset = createSyntaxValidator({ preset: options?.preset });
2064
+ const entries = addresses === void 0 ? syntaxFixtures : own(addresses);
2065
+ const valid = [];
2066
+ const invalid = [];
2067
+ for (const { address, description } of entries) {
2068
+ const result = validator.parse(address);
2069
+ const described = description === void 0 ? {} : { description };
2070
+ if (result.ok) {
2071
+ const changed = !preset.isValid(address);
2072
+ valid.push({
2073
+ address,
2074
+ ...described,
2075
+ changed
2076
+ });
2077
+ } else {
2078
+ const { ok: _, ...failure } = result;
2079
+ invalid.push({
2080
+ address,
2081
+ ...described,
2082
+ ...failure,
2083
+ changed: preset.isValid(address)
2084
+ });
2085
+ }
2086
+ }
2087
+ return {
2088
+ valid,
2089
+ invalid
2090
+ };
2091
+ }
2092
+ /** Checks the caller's addresses, before any of them is parsed. */
2093
+ function own(addresses) {
2094
+ if (!Array.isArray(addresses)) throw new TypeError("Expected the addresses to be an array");
2095
+ return addresses.map((address, i) => {
2096
+ if (typeof address !== "string") throw new TypeError(`Expected addresses[${i}] to be a string`);
2097
+ return { address };
2098
+ });
2099
+ }
2100
+ //#endregion
2101
+ export { isemailFixtures, legacyFixtures, presets, previewSyntaxOptions, rfc3696Fixtures, supportMatrix, syntaxFeatures, syntaxFixtures, wikipediaFixtures };
2102
+
2103
+ //# sourceMappingURL=fixtures.mjs.map