Skip to content

Commit 3b5f268

Browse files
authored
Merge pull request #1160 from b4ldr/Stdlib__Email
Stdlib::Email type
2 parents 2dedbb9 + ea1557b commit 3b5f268

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

spec/type_aliases/email_spec.rb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
require 'spec_helper'
2+
3+
# Test cases are a combination of the test cases used in MediaWiki[1] and a
4+
# Reference found on line[2]. Some of the test cases in the later list have
5+
# been dropped as the regex used in the HTML5 specification[3] (and in this type)
6+
# allows for wilful violation of the RFC's
7+
#
8+
# [1]https://github.com/wikimedia/mediawiki/blob/master/tests/phpunit/integration \
9+
# /includes/SanitizerValidateEmailTest.php
10+
# [2]https://gist.github.com/cjaoude/fd9910626629b53c4d25
11+
# [3]https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
12+
13+
describe 'Stdlib::Email' do
14+
describe 'valid handling' do
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
'email@example',
30+
31+
'user@a'].each do |value|
32+
describe value.inspect do
33+
it { is_expected.to allow_value(value) }
34+
end
35+
end
36+
end
37+
describe 'invalid handling' do
38+
['plainaddress',
39+
'#@%^%#$@#$@#.com',
40+
'@example.com',
41+
42+
43+
44+
45+
'useremail@example com',
46+
47+
'useremail@example,com',
48+
'useremail@.',
49+
50+
'useremail@a......',
51+
'useràexample.com',
52+
'Joe Smith <[email protected]>',
53+
'email.example.com',
54+
55+
'あいうえお@example.com',
56+
'[email protected] (Joe Smith)',
57+
58+
59+
'”(),:;<>[\]@example.com',
60+
'just”not”[email protected]',
61+
'this\ is"really"not\[email protected]'].each do |value|
62+
describe value.inspect do
63+
it { is_expected.not_to allow_value(value) }
64+
end
65+
end
66+
end
67+
end

types/email.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
2+
type Stdlib::Email = Pattern[/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/]

0 commit comments

Comments
 (0)