From dad60e78010384b93712327ccf0eac45d077b815 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 28 Jan 2007 14:16:25 +0000 Subject: mail_to :encode => 'hex' also encodes the mailto: part of the href attribute as well as the linked email when no name is given. Closes #2061. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6070 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/url_helper.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 4e911b94bf..688790094b 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -273,7 +273,7 @@ module ActionView # My email def mail_to(email_address, name = nil, html_options = {}) html_options = html_options.stringify_keys - encode = html_options.delete("encode") + encode = html_options.delete("encode").to_s cc, bcc, subject, body = html_options.delete("cc"), html_options.delete("bcc"), html_options.delete("subject"), html_options.delete("body") string = '' @@ -297,6 +297,14 @@ module ActionView end "" elsif encode == "hex" + email_address_encoded = '' + email_address_obfuscated.each_byte do |c| + email_address_encoded << sprintf("&#%d;", c) + end + + protocol = 'mailto:' + protocol.each_byte { |c| string << sprintf("&#%d;", c) } + for i in 0...email_address.length if email_address[i,1] =~ /\w/ string << sprintf("%%%x",email_address[i]) @@ -304,7 +312,7 @@ module ActionView string << email_address[i,1] end end - content_tag "a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:#{string}#{extras}" }) + content_tag "a", name || email_address_encoded, html_options.merge({ "href" => "#{string}#{extras}" }) else content_tag "a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:#{email_address}#{extras}" }) end -- cgit v1.2.3