aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/url_helper.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-01-28 14:16:25 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-01-28 14:16:25 +0000
commitdad60e78010384b93712327ccf0eac45d077b815 (patch)
tree1846094b97d5c5a0c2bf43205bb07dc58ac46840 /actionpack/lib/action_view/helpers/url_helper.rb
parent5224b62ae360d35891e562918a438ab4761ecf1f (diff)
downloadrails-dad60e78010384b93712327ccf0eac45d077b815.tar.gz
rails-dad60e78010384b93712327ccf0eac45d077b815.tar.bz2
rails-dad60e78010384b93712327ccf0eac45d077b815.zip
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
Diffstat (limited to 'actionpack/lib/action_view/helpers/url_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb12
1 files changed, 10 insertions, 2 deletions
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
# <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
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
"<script type=\"text/javascript\">eval(unescape('#{string}'))</script>"
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