Skip to content

Commit

Permalink
fixing autolinking other protocols
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#3494 state:committed]
  • Loading branch information
zbrock authored and NZKoz committed Jan 4, 2010
1 parent c362a76 commit f32c96e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -548,7 +548,7 @@ def auto_link_urls(text, html_options = {})
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
# do not change string; URL is already linked
href
else
# don't include trailing punctuation character as part of the URL
Expand All @@ -560,7 +560,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
end
Expand Down
14 changes: 14 additions & 0 deletions actionpack/test/template/text_helper_test.rb
Expand Up @@ -356,6 +356,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')
Expand Down

0 comments on commit f32c96e

Please sign in to comment.