Skip to content

Stdlib::Email type #1160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions spec/type_aliases/email_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'spec_helper'

# Test cases are a combination of the test cases used in MediaWiki[1] and a
# Reference found on line[2]. Some of the test cases in the later list have
# been dropped as the regex used in the HTML5 specification[3] (and in this type)
# allows for wilful violation of the RFC's
#
# [1]https://github.com/wikimedia/mediawiki/blob/master/tests/phpunit/integration \
# /includes/SanitizerValidateEmailTest.php
# [2]https://gist.github.com/cjaoude/fd9910626629b53c4d25
# [3]https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address

describe 'Stdlib::Email' do
describe 'valid handling' do
['[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'email@example',
'[email protected]',
'user@a'].each do |value|
describe value.inspect do
it { is_expected.to allow_value(value) }
end
end
end
describe 'invalid handling' do
['plainaddress',
'#@%^%#$@#$@#.com',
'@example.com',
' [email protected]',
'[email protected] ',
"[email protected]\t",
'user [email protected]',
'useremail@example com',
'user,[email protected]',
'useremail@example,com',
'useremail@.',
'[email protected]',
'useremail@a......',
'useràexample.com',
'Joe Smith <[email protected]>',
'email.example.com',
'email@[email protected]',
'あいうえお@example.com',
'[email protected] (Joe Smith)',
'[email protected]',
'[email protected]',
'”(),:;<>[\]@example.com',
'just”not”[email protected]',
'this\ is"really"not\[email protected]'].each do |value|
describe value.inspect do
it { is_expected.not_to allow_value(value) }
end
end
end
end
2 changes: 2 additions & 0 deletions types/email.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
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])?)*$/]