aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-09-30 15:10:52 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-09-30 15:10:52 -0300
commit1f14b9f535682217d855ef382c3b85314066c5ab (patch)
tree7e4e78c2903b17fa7a6362d2490b7addad49b296
parent09975bb24c56f00d47fce1b37dffe25be0a9a167 (diff)
parent0e50b7bdf4c0f789db37e22dc45c52b082f674b4 (diff)
downloadrails-1f14b9f535682217d855ef382c3b85314066c5ab.tar.gz
rails-1f14b9f535682217d855ef382c3b85314066c5ab.tar.bz2
rails-1f14b9f535682217d855ef382c3b85314066c5ab.zip
Merge pull request #17113 from igor04/helpers-highlight
Added processing of `nil` to `highlight` helper method
-rw-r--r--actionview/lib/action_view/helpers/text_helper.rb2
-rw-r--r--actionview/test/template/text_helper_test.rb4
2 files changed, 5 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb
index b859653bc9..a9f1631586 100644
--- a/actionview/lib/action_view/helpers/text_helper.rb
+++ b/actionview/lib/action_view/helpers/text_helper.rb
@@ -126,7 +126,7 @@ module ActionView
text = sanitize(text) if options.fetch(:sanitize, true)
if text.blank? || phrases.blank?
- text
+ text || ""
else
match = Array(phrases).map do |p|
Regexp === p ? p.to_s : Regexp.escape(p)
diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb
index 667f9002da..f05b845e46 100644
--- a/actionview/test/template/text_helper_test.rb
+++ b/actionview/test/template/text_helper_test.rb
@@ -193,6 +193,10 @@ class TextHelperTest < ActionView::TestCase
assert_equal ' ', highlight(' ', 'blank text is returned verbatim')
end
+ def test_highlight_should_return_blank_string_for_nil
+ assert_equal '', highlight(nil, 'blank string is returned for nil')
+ end
+
def test_highlight_should_sanitize_input
assert_equal(
"This is a <mark>beautiful</mark> morning",