From 6d17ece9f2558fe6d64a97d0b99493e4de2d32eb Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 3 Sep 2006 16:47:05 +0000 Subject: strip_tags returns nil for a blank arg such as nil or "". Closes #2229. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4916 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/text_helper.rb | 3 ++- actionpack/test/template/text_helper_test.rb | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index d8fe2ab5ab..73a2e6f4fe 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* strip_tags returns nil for a blank arg such as nil or "". #2229 [duncan@whomwah.com] + * Cleanup assert_tag :children counting. #2181 [jamie@bravenet.com] * button_to accepts :method so you can PUT and DELETE with it. #6005 [Dan Webb] diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 8b724127a2..36ed899cf0 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -213,7 +213,8 @@ module ActionView # tokenizer and so it's HTML parsing ability is limited by that of html-scanner. # # Returns the tag free text. - def strip_tags(html) + def strip_tags(html) + return nil if html.blank? if html.index("<") text = "" tokenizer = HTML::Tokenizer.new(html) diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 7cc92e0bd6..6eda59affe 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -314,7 +314,7 @@ class TextHelperTest < Test::Unit::TestCase assert_equal( %{This is a test.\n\n\nIt no longer contains any HTML.\n}, strip_tags( %{This is <b>a <a href="" target="_blank">test</a></b>.\n\n\n\n

It no longer contains any HTML.

\n})) - assert_equal("This has a here.", strip_tags("This has a here.")) + assert_equal "This has a here.", strip_tags("This has a here.") + [nil, '', ' '].each { |blank| assert_nil strip_tags(blank) } end - end -- cgit v1.2.3