Skip to content

Commit 788274b

Browse files
authored
Merge pull request #124 from nlevchuk/prohibit-leading-and-trailing-dots-in-email-regexp
The local part should not contain leading or trailing dots in the EMAIL_REGEXP
2 parents 0c2b646 + 2d7d2d9 commit 788274b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/uri/mailto.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class MailTo < Generic
5252
HEADER_REGEXP = /\A(?<hfield>(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g<hfield>)*\z/
5353
# practical regexp for email address
5454
# https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
55-
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/
55+
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/
5656
# :startdoc:
5757

5858
#

test/uri/test_mailto.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,30 @@ def test_initializer
141141
def test_check_to
142142
u = URI::MailTo.build(['[email protected]', 'subject=Ruby'])
143143

144+
# Valid emails
145+
146+
assert_equal(u.to, '[email protected]')
147+
148+
# Invalid emails
144149
assert_raise(URI::InvalidComponentError) do
145150
146151
end
147152

148153
assert_raise(URI::InvalidComponentError) do
149154
u.to = '@invalid.email'
150155
end
156+
157+
assert_raise(URI::InvalidComponentError) do
158+
159+
end
160+
161+
assert_raise(URI::InvalidComponentError) do
162+
163+
end
164+
165+
assert_raise(URI::InvalidComponentError) do
166+
167+
end
151168
end
152169

153170
def test_to_s

0 commit comments

Comments
 (0)