@email-utils/validator-syntax 0.0.1-9 → 1.0.0-rc.2

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