aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach Brock <zbrock@gmail.com>2009-11-24 23:51:51 -0800
committerMichael Koziarski <michael@koziarski.com>2010-01-05 10:57:20 +1300
commit79438b46382aa08ea83d740247eb16365e6d2327 (patch)
tree2b03ebad4c612392e1dc9bc59d64a0f38a6d5d66
parentae270f597decb66444d91b27509c7dc1fc24a6b6 (diff)
downloadrails-79438b46382aa08ea83d740247eb16365e6d2327.tar.gz
rails-79438b46382aa08ea83d740247eb16365e6d2327.tar.bz2
rails-79438b46382aa08ea83d740247eb16365e6d2327.zip
adding fix for auto linking to master too
Signed-off-by: Michael Koziarski <michael@koziarski.com>
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb2
-rw-r--r--actionpack/test/template/text_helper_test.rb14
2 files changed, 15 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 1d92bcb763..be15e227b9 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -567,7 +567,7 @@ module ActionView
end
link_text = block_given?? yield(href) : href
- href = 'http://' + href unless href.index('http') == 0
+ href = 'http://' + href unless href =~ %r{^[a-z]+://}i
content_tag(:a, h(link_text), link_attributes.merge('href' => href)) + punctuation.reverse.join('')
end
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 08143ba680..088c07b8bb 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -360,6 +360,20 @@ class TextHelperTest < ActionView::TestCase
assert_equal %(<p>#{link10_result} Link</p>), auto_link("<p>#{link10_raw} Link</p>")
end
+ def test_auto_link_other_protocols
+ silence_warnings do
+ begin
+ old_re_value = ActionView::Helpers::TextHelper::AUTO_LINK_RE
+ ActionView::Helpers::TextHelper.const_set :AUTO_LINK_RE, %r{(ftp://)[^\s<]+}
+ link_raw = 'ftp://example.com/file.txt'
+ link_result = generate_result(link_raw)
+ assert_equal %(Download #{link_result}), auto_link("Download #{link_raw}")
+ ensure
+ ActionView::Helpers::TextHelper.const_set :AUTO_LINK_RE, old_re_value
+ end
+ end
+ end
+
def test_auto_link_already_linked
linked1 = generate_result('Ruby On Rails', 'http://www.rubyonrails.com')
linked2 = generate_result('www.rubyonrails.com', 'http://www.rubyonrails.com')