Skip to content
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

Encode the email address as prescribed in RFC 6068 section 2. #21007

Merged
merged 1 commit into from
Jul 24, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion actionview/lib/action_view/helpers/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ def mail_to(email_address, name = nil, html_options = {}, &block)
}.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
Expand Down
7 changes: 7 additions & 0 deletions actionview/test/template/url_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,13 @@ def test_mail_to
mail_to("david@loudthinking.com", "David Heinemeier Hansson", class: "admin")
end

def test_mail_to_with_special_characters
assert_dom_equal(
%{<a href="mailto:%23%21%24%25%26%27%2A%2B-%2F%3D%3F%5E_%60%7B%7D%7C%7E@example.org">#!$%&amp;&#39;*+-/=?^_`{}|~@example.org</a>},
mail_to("#!$%&'*+-/=?^_`{}|~@example.org")
)
end

def test_mail_with_options
assert_dom_equal(
%{<a href="mailto:me@example.com?cc=ccaddress%40example.com&amp;bcc=bccaddress%40example.com&amp;body=This%20is%20the%20body%20of%20the%20message.&amp;subject=This%20is%20an%20example%20email&amp;reply-to=foo%40bar.com">My email</a>},
Expand Down