diff options
author | Nikita Levchuk <[email protected]> | 2024-12-06 11:56:03 +0100 |
---|---|---|
committer | git <[email protected]> | 2025-07-12 03:31:54 +0000 |
commit | c97eba9bcd6188f39c827be3b40d29cef26c8eac (patch) | |
tree | d9e6b787db66dc7b08cb828343f34cabb09e73f8 | |
parent | 0685e8caf9550c2b4e3c378ab1656c3139b96596 (diff) |
[ruby/uri] lib/uri/mailto.rb (EMAIL_REGEXP): use assertions surrounding the local part instead of a character classHEADmaster
https://github.com/ruby/uri/commit/2d7d2d9988
-rw-r--r-- | lib/uri/mailto.rb | 2 | ||||
-rw-r--r-- | test/uri/test_mailto.rb | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb index c5a5e4ae26..a15d2f0fba 100644 --- a/lib/uri/mailto.rb +++ b/lib/uri/mailto.rb @@ -52,7 +52,7 @@ module URI 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 - 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: # diff --git a/test/uri/test_mailto.rb b/test/uri/test_mailto.rb index d2e9648299..e7c04ef068 100644 --- a/test/uri/test_mailto.rb +++ b/test/uri/test_mailto.rb @@ -141,6 +141,11 @@ class URI::TestMailTo < Test::Unit::TestCase def test_check_to u = URI::MailTo.build(['[email protected]', 'subject=Ruby']) + # Valid emails + u.to = '[email protected]' + assert_equal(u.to, '[email protected]') + + # Invalid emails assert_raise(URI::InvalidComponentError) do u.to = '#[email protected]' end @@ -156,6 +161,10 @@ class URI::TestMailTo < Test::Unit::TestCase assert_raise(URI::InvalidComponentError) do u.to = '[email protected]' end + + assert_raise(URI::InvalidComponentError) do + u.to = '[email protected]' + end end def test_to_s |