Skip to content

Commit bdfa733

Browse files
libclifo
authored andcommitted
Ensure auto_link doesnt linkify URLs in the middle of a tag [#1523 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
1 parent 1dff106 commit bdfa733

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

actionpack/lib/action_view/helpers/text_helper.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,9 @@ def auto_link_urls(text, html_options = {})
536536
text.gsub(AUTO_LINK_RE) do
537537
href = $&
538538
punctuation = ''
539-
# detect already linked URLs
540-
if $` =~ /<a\s[^>]*href="$/
539+
left, right = $`, $'
540+
# detect already linked URLs and URLs in the middle of a tag
541+
if left =~ /<[^>]+$/ && right =~ /^[^>]*>/
541542
# do not change string; URL is alreay linked
542543
href
543544
else

actionpack/test/template/text_helper_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ def test_auto_link_with_brackets
375375
assert_equal "{link: #{link3_result}}", auto_link("{link: #{link3_raw}}")
376376
end
377377

378+
def test_auto_link_in_tags
379+
link_raw = 'http://www.rubyonrails.org/images/rails.png'
380+
link_result = %Q(<img src="#{link_raw}" />)
381+
assert_equal link_result, auto_link(link_result)
382+
end
383+
378384
def test_auto_link_at_eol
379385
url1 = "http://api.rubyonrails.com/Foo.html"
380386
url2 = "http://www.ruby-doc.org/core/Bar.html"

0 commit comments

Comments
 (0)