Skip to content

Commit e8e406f

Browse files
committed
Extend email format tests
Before this, a simple /@/ check passed this format test. This now extends the test a bit more, to check that obviously invalid domains are rejected, and that local part is checked at least for something. Symbol check + dot position check is a good indication here, because: 1) It's common and doesn't need implementing complex quotes logic 2) Dot is the only symbol which validity depends on the position in the local part This should trigger most of the naive implementations (e.g. /@/) and is still not hard to implement as it doesn't include quoted strings support. JSON Schema uses RFC 5322. Refs: https://tools.ietf.org/html/rfc5322#page-17 Refs: https://tools.ietf.org/html/rfc5322#page-12
1 parent 1f34d33 commit e8e406f

File tree

5 files changed

+225
-0
lines changed

5 files changed

+225
-0
lines changed

tests/draft2019-09/optional/format/email.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,51 @@
1212
"description": "an invalid e-mail address",
1313
"data": "2962",
1414
"valid": false
15+
},
16+
{
17+
"description": "tilde in local part is valid",
18+
"data": "te~st@example.com",
19+
"valid": true
20+
},
21+
{
22+
"description": "tilde before local part is valid",
23+
"data": "~test@example.com",
24+
"valid": true
25+
},
26+
{
27+
"description": "tilde after local part is valid",
28+
"data": "test~@example.com",
29+
"valid": true
30+
},
31+
{
32+
"description": "dot before local part is not valid",
33+
"data": ".test@example.com",
34+
"valid": false
35+
},
36+
{
37+
"description": "dot after local part is not valid",
38+
"data": "test.@example.com",
39+
"valid": false
40+
},
41+
{
42+
"description": "two separated dots inside local part are valid",
43+
"data": "te.s.t@example.com",
44+
"valid": true
45+
},
46+
{
47+
"description": "two subsequent dots inside local part are not valid",
48+
"data": "te..st@example.com",
49+
"valid": false
50+
},
51+
{
52+
"description": "space in domain is not valid",
53+
"data": "test@example .com",
54+
"valid": false
55+
},
56+
{
57+
"description": "symbol in domain is not valid",
58+
"data": "test@example&.com",
59+
"valid": false
1560
}
1661
]
1762
}

tests/draft3/optional/format/email.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,51 @@
1212
"description": "an invalid e-mail address",
1313
"data": "2962",
1414
"valid": false
15+
},
16+
{
17+
"description": "tilde in local part is valid",
18+
"data": "te~st@example.com",
19+
"valid": true
20+
},
21+
{
22+
"description": "tilde before local part is valid",
23+
"data": "~test@example.com",
24+
"valid": true
25+
},
26+
{
27+
"description": "tilde after local part is valid",
28+
"data": "test~@example.com",
29+
"valid": true
30+
},
31+
{
32+
"description": "dot before local part is not valid",
33+
"data": ".test@example.com",
34+
"valid": false
35+
},
36+
{
37+
"description": "dot after local part is not valid",
38+
"data": "test.@example.com",
39+
"valid": false
40+
},
41+
{
42+
"description": "two separated dots inside local part are valid",
43+
"data": "te.s.t@example.com",
44+
"valid": true
45+
},
46+
{
47+
"description": "two subsequent dots inside local part are not valid",
48+
"data": "te..st@example.com",
49+
"valid": false
50+
},
51+
{
52+
"description": "space in domain is not valid",
53+
"data": "test@example .com",
54+
"valid": false
55+
},
56+
{
57+
"description": "symbol in domain is not valid",
58+
"data": "test@example&.com",
59+
"valid": false
1560
}
1661
]
1762
}

tests/draft4/optional/format/email.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,51 @@
1212
"description": "an invalid e-mail address",
1313
"data": "2962",
1414
"valid": false
15+
},
16+
{
17+
"description": "tilde in local part is valid",
18+
"data": "te~st@example.com",
19+
"valid": true
20+
},
21+
{
22+
"description": "tilde before local part is valid",
23+
"data": "~test@example.com",
24+
"valid": true
25+
},
26+
{
27+
"description": "tilde after local part is valid",
28+
"data": "test~@example.com",
29+
"valid": true
30+
},
31+
{
32+
"description": "dot before local part is not valid",
33+
"data": ".test@example.com",
34+
"valid": false
35+
},
36+
{
37+
"description": "dot after local part is not valid",
38+
"data": "test.@example.com",
39+
"valid": false
40+
},
41+
{
42+
"description": "two separated dots inside local part are valid",
43+
"data": "te.s.t@example.com",
44+
"valid": true
45+
},
46+
{
47+
"description": "two subsequent dots inside local part are not valid",
48+
"data": "te..st@example.com",
49+
"valid": false
50+
},
51+
{
52+
"description": "space in domain is not valid",
53+
"data": "test@example .com",
54+
"valid": false
55+
},
56+
{
57+
"description": "symbol in domain is not valid",
58+
"data": "test@example&.com",
59+
"valid": false
1560
}
1661
]
1762
}

tests/draft6/optional/format/email.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,51 @@
1212
"description": "an invalid e-mail address",
1313
"data": "2962",
1414
"valid": false
15+
},
16+
{
17+
"description": "tilde in local part is valid",
18+
"data": "te~st@example.com",
19+
"valid": true
20+
},
21+
{
22+
"description": "tilde before local part is valid",
23+
"data": "~test@example.com",
24+
"valid": true
25+
},
26+
{
27+
"description": "tilde after local part is valid",
28+
"data": "test~@example.com",
29+
"valid": true
30+
},
31+
{
32+
"description": "dot before local part is not valid",
33+
"data": ".test@example.com",
34+
"valid": false
35+
},
36+
{
37+
"description": "dot after local part is not valid",
38+
"data": "test.@example.com",
39+
"valid": false
40+
},
41+
{
42+
"description": "two separated dots inside local part are valid",
43+
"data": "te.s.t@example.com",
44+
"valid": true
45+
},
46+
{
47+
"description": "two subsequent dots inside local part are not valid",
48+
"data": "te..st@example.com",
49+
"valid": false
50+
},
51+
{
52+
"description": "space in domain is not valid",
53+
"data": "test@example .com",
54+
"valid": false
55+
},
56+
{
57+
"description": "symbol in domain is not valid",
58+
"data": "test@example&.com",
59+
"valid": false
1560
}
1661
]
1762
}

tests/draft7/optional/format/email.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,51 @@
1212
"description": "an invalid e-mail address",
1313
"data": "2962",
1414
"valid": false
15+
},
16+
{
17+
"description": "tilde in local part is valid",
18+
"data": "te~st@example.com",
19+
"valid": true
20+
},
21+
{
22+
"description": "tilde before local part is valid",
23+
"data": "~test@example.com",
24+
"valid": true
25+
},
26+
{
27+
"description": "tilde after local part is valid",
28+
"data": "test~@example.com",
29+
"valid": true
30+
},
31+
{
32+
"description": "dot before local part is not valid",
33+
"data": ".test@example.com",
34+
"valid": false
35+
},
36+
{
37+
"description": "dot after local part is not valid",
38+
"data": "test.@example.com",
39+
"valid": false
40+
},
41+
{
42+
"description": "two separated dots inside local part are valid",
43+
"data": "te.s.t@example.com",
44+
"valid": true
45+
},
46+
{
47+
"description": "two subsequent dots inside local part are not valid",
48+
"data": "te..st@example.com",
49+
"valid": false
50+
},
51+
{
52+
"description": "space in domain is not valid",
53+
"data": "test@example .com",
54+
"valid": false
55+
},
56+
{
57+
"description": "symbol in domain is not valid",
58+
"data": "test@example&.com",
59+
"valid": false
1560
}
1661
]
1762
}

0 commit comments

Comments
 (0)