From 6a387824775430fef2a0075ddd7b9d31e8c5cb48 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Thu, 23 Jul 2015 16:36:13 -0400 Subject: Encode the email address as prescribed in RFC 6068 section 2. --- actionview/lib/action_view/helpers/url_helper.rb | 3 ++- actionview/test/template/url_helper_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index afb1265ad9..7d92651183 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -468,7 +468,8 @@ module ActionView }.compact extras = extras.empty? ? '' : '?' + extras.join('&') - html_options["href"] = "mailto:#{email_address}#{extras}" + encoded_email_address = ERB::Util.url_encode(email_address).gsub("%40", "@") + html_options["href"] = "mailto:#{encoded_email_address}#{extras}" content_tag(:a, name || email_address, html_options, &block) end diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 0e35c67516..416d30938a 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -500,6 +500,13 @@ class UrlHelperTest < ActiveSupport::TestCase mail_to("david@loudthinking.com", "David Heinemeier Hansson", class: "admin") end + def test_mail_to_with_special_characters + assert_dom_equal( + %{#!$%&'*+-/=?^_`{}|~@example.org}, + mail_to("#!$%&'*+-/=?^_`{}|~@example.org") + ) + end + def test_mail_with_options assert_dom_equal( %{My email}, -- cgit v1.2.3