aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers
diff options
context:
space:
mode:
authorNihad Abbasov <narkoz.2008@gmail.com>2012-12-24 20:56:32 +0400
committerNihad Abbasov <narkoz.2008@gmail.com>2012-12-24 20:56:32 +0400
commit513331d114b4ad683e85c0158f7f596cad315cb5 (patch)
tree246122946317520bd8eae8748a0bef7e1553b19f /actionpack/lib/action_view/helpers
parentef5d85709d346e55827e88f53430a2cbe1e5fb9e (diff)
downloadrails-513331d114b4ad683e85c0158f7f596cad315cb5.tar.gz
rails-513331d114b4ad683e85c0158f7f596cad315cb5.tar.bz2
rails-513331d114b4ad683e85c0158f7f596cad315cb5.zip
fetch highlighter option only when needed
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb4
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