diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 1dad31d9e6..e65526ff27 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make auto_link handle nil by returning quickly if blank? [Scott Barron] + * Make auto_link match urls with a port number specified. [Marcel Molina Jr.] * Added support for toggling visual effects to ScriptaculousHelper::visual_effect, #3323. [Thomas Fuchs] diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 1b1ca386c2..856c997e9a 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -142,6 +142,7 @@ module ActionView # truncate(text, 15) # end def auto_link(text, link = :all, href_options = {}, &block) + return '' if text.blank? case link when :all then auto_link_urls(auto_link_email_addresses(text, &block), href_options, &block) when :email_addresses then auto_link_email_addresses(text, &block) diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 37c81e12a6..b323568068 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -155,6 +155,8 @@ class TextHelperTest < Test::Unit::TestCase assert_equal %(
Link #{link4_result}
), auto_link("Link #{link4_raw}
") assert_equal %(#{link4_result} Link
), auto_link("#{link4_raw} Link
") assert_equal %(#{link5_result} Link
), auto_link("#{link5_raw} Link
") + assert_equal '', auto_link(nil) + assert_equal '', auto_link('') end def test_auto_link_at_eol