Skip to content
Browse files

adding fix for auto linking to master too

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent ae270f5 commit 79438b46382aa08ea83d740247eb16365e6d2327 @zbrock zbrock committed with NZKoz Nov 24, 2009
Showing with 15 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_view/helpers/text_helper.rb
  2. +14 −0 actionpack/test/template/text_helper_test.rb
View
2 actionpack/lib/action_view/helpers/text_helper.rb
@@ -567,7 +567,7 @@ def auto_link_urls(text, html_options = {})
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
View
14 actionpack/test/template/text_helper_test.rb
@@ -360,6 +360,20 @@ def test_auto_linking
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')

0 comments on commit 79438b4

Please sign in to comment.
Something went wrong with that request. Please try again.