Added processing of nil
to highlight
helper method
This commit is contained in:
parent
79c491e838
commit
0e50b7bdf4
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user