Skip to content

Commit

Permalink
Merge pull request #17113 from igor04/helpers-highlight
Browse files Browse the repository at this point in the history
Added processing of `nil` to `highlight` helper method
  • Loading branch information
rafaelfranca committed Sep 30, 2014
2 parents 09975bb + 0e50b7b commit 1f14b9f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/text_helper.rb
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions actionview/test/template/text_helper_test.rb
Expand Up @@ -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",
Expand Down

0 comments on commit 1f14b9f

Please sign in to comment.