Skip to content

Commit

Permalink
Fixed autolink bug in text_helper.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
mdh committed Feb 3, 2009
1 parent 34a37ea commit a4b672c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions actionpack/lib/action_view/helpers/text_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,10 @@ def auto_link_email_addresses(text, html_options = {})
body = text.dup
text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do
text = $1

if body.match(/<a\b[^>]*>(.*)(#{Regexp.escape(text)})(.*)<\/a>/)
last_string = $`
if last_string =~ /mailto:$/i || last_string =~ /mailto:#{text}\"\>$/i
text
elsif body.match(/<a\b[^>]*>(.*)(#{Regexp.escape(text)})(.*)<\/a>/)
text
else
display_text = (block_given?) ? yield(text) : text
Expand Down
3 changes: 3 additions & 0 deletions actionpack/test/template/text_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ def test_auto_link_already_linked
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 = %(<a href="mailto:#{email_raw}">Mail me!</a>)
assert_equal email_linked, auto_link(email_linked)
end

def test_auto_link_with_brackets
Expand Down

0 comments on commit a4b672c

Please sign in to comment.