提交 0e50b7bd 编写于 作者: I igor04

Added processing of `nil` to `highlight` helper method

上级 79c491e8
......@@ -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",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册