mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05: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:
parent
1dff106888
commit
bdfa733d04
2 changed files with 9 additions and 2 deletions
|
@ -536,8 +536,9 @@ module ActionView
|
||||||
text.gsub(AUTO_LINK_RE) do
|
text.gsub(AUTO_LINK_RE) do
|
||||||
href = $&
|
href = $&
|
||||||
punctuation = ''
|
punctuation = ''
|
||||||
# detect already linked URLs
|
left, right = $`, $'
|
||||||
if $` =~ /<a\s[^>]*href="$/
|
# detect already linked URLs and URLs in the middle of a tag
|
||||||
|
if left =~ /<[^>]+$/ && right =~ /^[^>]*>/
|
||||||
# do not change string; URL is alreay linked
|
# do not change string; URL is alreay linked
|
||||||
href
|
href
|
||||||
else
|
else
|
||||||
|
|
|
@ -375,6 +375,12 @@ class TextHelperTest < ActionView::TestCase
|
||||||
assert_equal "{link: #{link3_result}}", auto_link("{link: #{link3_raw}}")
|
assert_equal "{link: #{link3_result}}", auto_link("{link: #{link3_raw}}")
|
||||||
end
|
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
|
def test_auto_link_at_eol
|
||||||
url1 = "http://api.rubyonrails.com/Foo.html"
|
url1 = "http://api.rubyonrails.com/Foo.html"
|
||||||
url2 = "http://www.ruby-doc.org/core/Bar.html"
|
url2 = "http://www.ruby-doc.org/core/Bar.html"
|
||||||
|
|
Loading…
Reference in a new issue