Skip to content
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
2 changes: 1 addition & 1 deletion lib/uri/mailto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MailTo < Generic
HEADER_REGEXP = /\A(?<hfield>(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g<hfield>)*\z/
# practical regexp for email address
# https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
Comment on lines 53 to 54
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unfortunate that there was no test cases to assert intentional violations to work, but as clearly mentioned in this comment right above the updated regexp, the leading/trailing/consecutive dots are intentionally allowed - otherwise it is considered a major breaking change. #189 (comment)

EMAIL_REGEXP = /\A[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])?)*\z/
EMAIL_REGEXP = /\A(?!\.)[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])?)*\z/
# :startdoc:

#
Expand Down
17 changes: 17 additions & 0 deletions test/uri/test_mailto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,30 @@ def test_initializer
def test_check_to
u = URI::MailTo.build(['joe@example.com', 'subject=Ruby'])

# Valid emails
u.to = 'a@valid.com'
assert_equal(u.to, 'a@valid.com')

# Invalid emails
assert_raise(URI::InvalidComponentError) do
u.to = '#1@mail.com'
end

assert_raise(URI::InvalidComponentError) do
u.to = '@invalid.email'
end

assert_raise(URI::InvalidComponentError) do
u.to = '.hello@invalid.email'
end

assert_raise(URI::InvalidComponentError) do
u.to = 'hello.@invalid.email'
end

assert_raise(URI::InvalidComponentError) do
u.to = 'n.@invalid.email'
end
end

def test_to_s
Expand Down
Loading