diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-09-02 23:52:01 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-09-02 23:52:01 +0000 |
commit | a79ac12c4e81c33991f079d6993ad5141190c17c (patch) | |
tree | 4e37b0fd799c4bb716de62ec947d9f996abeaf12 /actionpack/lib/action_view | |
parent | bde8be41fb3141e33dc86e24fa3fe6200cbb9e87 (diff) | |
download | rails-a79ac12c4e81c33991f079d6993ad5141190c17c.tar.gz rails-a79ac12c4e81c33991f079d6993ad5141190c17c.tar.bz2 rails-a79ac12c4e81c33991f079d6993ad5141190c17c.zip |
Make auto link behave well with URLs containing email addresses. Closes #7313 [jeremymcnally]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7397 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/text_helper.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 8db8ce7009..9a8f0115ad 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -305,7 +305,7 @@ module ActionView def auto_link(text, link = :all, href_options = {}, &block) return '' if text.blank? case link - when :all then auto_link_urls(auto_link_email_addresses(text, &block), href_options, &block) + when :all then auto_link_email_addresses(auto_link_urls(text, href_options, &block), &block) when :email_addresses then auto_link_email_addresses(text, &block) when :urls then auto_link_urls(text, href_options, &block) end @@ -534,8 +534,8 @@ module ActionView [-\w]+ # subdomain or domain (?:\.[-\w]+)* # remaining subdomains or domain (?::\d+)? # port - (?:/(?:(?:[~\w\+%-]|(?:[,.;:][^\s$]))+)?)* # path - (?:\?[\w\+%&=.;-]+)? # query string + (?:/(?:(?:[~\w\+@%-]|(?:[,.;:][^\s$]))+)?)* # path + (?:\?[\w\+@%&=.;-]+)? # query string (?:\#[\w\-]*)? # trailing anchor ) ([[:punct:]]|\s|<|$) # trailing text @@ -560,10 +560,16 @@ module ActionView # Turns all email addresses into clickable links. If a block is given, # each email is yielded and the result is used as the link text. def auto_link_email_addresses(text) + body = text.dup text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do text = $1 - text = yield(text) if block_given? - %{<a href="mailto:#{$1}">#{text}</a>} + + if body.match(/<a\b[^>]*>(.*)(#{text})(.*)<\/a>/) + text + else + display_text = (block_given?) ? yield(text) : text + %{<a href="mailto:#{text}">#{display_text}</a>} + end end end end |