diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2012-12-26 14:06:13 -0800 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2012-12-26 14:06:13 -0800 |
commit | 14a61bba4dda8a48a1949960ee31e28973473916 (patch) | |
tree | a65852e13628ba4270a18da4b3f381a88262c7d7 /actionpack | |
parent | 78fd14c8de9577f92ee78ba399ca716589465465 (diff) | |
parent | 513331d114b4ad683e85c0158f7f596cad315cb5 (diff) | |
download | rails-14a61bba4dda8a48a1949960ee31e28973473916.tar.gz rails-14a61bba4dda8a48a1949960ee31e28973473916.tar.bz2 rails-14a61bba4dda8a48a1949960ee31e28973473916.zip |
Merge pull request #8598 from NARKOZ/refactor-highlight
refactor highlight method: return fast if text or phrases are blank
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/text_helper.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 26d2142df9..2e124cf085 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -112,12 +112,12 @@ module ActionView # highlight('You searched for: rails', 'rails', highlighter: '<a href="search?q=\1">\1</a>') # # => You searched for: <a href="search?q=rails">rails</a> def highlight(text, phrases, options = {}) - highlighter = options.fetch(:highlighter, '<mark>\1</mark>') - text = sanitize(text) if options.fetch(:sanitize, true) + if text.blank? || phrases.blank? text else + highlighter = options.fetch(:highlighter, '<mark>\1</mark>') match = Array(phrases).map { |p| Regexp.escape(p) }.join('|') text.gsub(/(#{match})(?![^<]*?>)/i, highlighter) end.html_safe |