Added processing of nil to highlight helper method

This commit is contained in:
igor04 2014-09-30 14:48:48 +03:00
parent 79c491e838
commit 0e50b7bdf4
2 changed files with 5 additions and 1 deletions

@ -126,7 +126,7 @@ def highlight(text, phrases, options = {})
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)

@ -193,6 +193,10 @@ def test_highlight_pending
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",