From 0e50b7bdf4c0f789db37e22dc45c52b082f674b4 Mon Sep 17 00:00:00 2001 From: igor04 Date: Tue, 30 Sep 2014 14:48:48 +0300 Subject: Added processing of `nil` to `highlight` helper method --- actionview/lib/action_view/helpers/text_helper.rb | 2 +- actionview/test/template/text_helper_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'actionview') 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 beautiful morning", -- cgit v1.2.3