aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorEugene Pimenov <libc@mac.com>2009-03-10 16:52:21 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-03-10 16:52:21 +0000
commitbdfa733d04c5843eadc181f2fd1723db614fc3d0 (patch)
treec5b64ce5a406ce0a91a8b910039e619908bc5126 /actionpack
parent1dff106888d671dac07f93711ecb319170132c56 (diff)
downloadrails-bdfa733d04c5843eadc181f2fd1723db614fc3d0.tar.gz
rails-bdfa733d04c5843eadc181f2fd1723db614fc3d0.tar.bz2
rails-bdfa733d04c5843eadc181f2fd1723db614fc3d0.zip
Ensure auto_link doesnt linkify URLs in the middle of a tag [#1523 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb5
-rw-r--r--actionpack/test/template/text_helper_test.rb6
2 files changed, 9 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 63fe0c1c57..48bf4717ad 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -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
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 564845779f..a370f1458f 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -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"