From 1d564d97c5216210be03862d90fd7ea222afdc52 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 26 Nov 2006 01:00:10 +0000 Subject: [PATCH] strip_tags passes through blank args such as nil or "". Closes #6702, references #2229. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5629 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 +- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- actionpack/test/template/text_helper_test.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index d5e347ad6cf08..a064526e06ec2 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -268,7 +268,7 @@ * radio_button_tag generates unique id attributes. #3353 [Bob Silva, somekool@gmail.com] -* strip_tags returns nil for a blank arg such as nil or "". #2229 [duncan@whomwah.com] +* strip_tags passes through blank args such as nil or "". #2229, #6702 [duncan@whomwah.com, dharana] * Cleanup assert_tag :children counting. #2181 [jamie@bravenet.com] diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 0b04bd323fbef..0b1b46b0f300f 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -254,7 +254,7 @@ def sanitize(html) # html-scanner tokenizer and so its HTML parsing ability is limited by # that of html-scanner. def strip_tags(html) - return nil if html.blank? + return html 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 8825a24f14c4e..bf008ae9df08f 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -321,6 +321,6 @@ def test_strip_tags %{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.") - [nil, '', ' '].each { |blank| assert_nil strip_tags(blank) } + [nil, '', ' '].each { |blank| assert_equal blank, strip_tags(blank) } end end