mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Ensure auto_link doesnt linkify URLs in the middle of a tag [#1523 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
committed by
Pratik Naik
parent
1dff106888
commit
bdfa733d04
@@ -536,8 +536,9 @@ module ActionView
|
||||
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 @@ class TextHelperTest < ActionView::TestCase
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user