Permalink
Browse files

Ensure auto_link doesnt linkify URLs in the middle of a tag [#1523 st…

…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 bdfa733d04c5843eadc181f2fd1723db614fc3d0
@@ -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
@@ -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"

0 comments on commit bdfa733

Please sign in to comment.