Skip to content

Commit

Permalink
Ensure auto_link doesnt linkify URLs in the middle of a tag [#1523 st…
Browse files Browse the repository at this point in the history
…ate:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
libc authored and lifo committed Mar 10, 2009
1 parent 1dff106 commit bdfa733
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -536,8 +536,9 @@ def auto_link_urls(text, html_options = {})
text.gsub(AUTO_LINK_RE) do
href = $&
punctuation = ''
# detect already linked URLs
if $` =~ /<a\s[^>]*href="$/
left, right = $`, $'
# detect already linked URLs and URLs in the middle of a tag
if left =~ /<[^>]+$/ && right =~ /^[^>]*>/
# do not change string; URL is alreay linked
href
else
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/template/text_helper_test.rb
Expand Up @@ -375,6 +375,12 @@ def test_auto_link_with_brackets
assert_equal "{link: #{link3_result}}", auto_link("{link: #{link3_raw}}")
end

def test_auto_link_in_tags
link_raw = 'http://www.rubyonrails.org/images/rails.png'
link_result = %Q(<img src="#{link_raw}" />)
assert_equal link_result, auto_link(link_result)
end

def test_auto_link_at_eol
url1 = "http://api.rubyonrails.com/Foo.html"
url2 = "http://www.ruby-doc.org/core/Bar.html"
Expand Down

0 comments on commit bdfa733

Please sign in to comment.