diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index b1eb689..f63d119 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -563,8 +563,10 @@ module ActionView body = text.dup text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do text = $1 - - if body.match(/]*>(.*)(#{Regexp.escape(text)})(.*)<\/a>/) + last_string = $` + if last_string =~ /mailto:$/i || last_string =~ /mailto:#{text}\"\>$/i + text + elsif body.match(/]*>(.*)(#{Regexp.escape(text)})(.*)<\/a>/) text else display_text = (block_given?) ? yield(text) : text diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 5648457..816b496 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -356,6 +356,9 @@ class TextHelperTest < ActionView::TestCase linked2 = generate_result('www.rubyonrails.com', 'http://www.rubyonrails.com') assert_equal linked1, auto_link(linked1) assert_equal linked2, auto_link(linked2) + email_raw = "david@loudthinking.com" + email_linked = %(Mail me!) + assert_equal email_linked, auto_link(email_linked) end def test_auto_link_with_brackets