aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2005-09-26 20:49:52 +0000
committerMarcel Molina <marcel@vernix.org>2005-09-26 20:49:52 +0000
commitb54560600b06112723adf286141a9cd7ed67b638 (patch)
tree07de49d0f78dbd5648af32e5d1abd656163a5e63 /actionpack/lib/action_view
parentbbfde01b944eecee9f51cb54d6452e6685d82b73 (diff)
downloadrails-b54560600b06112723adf286141a9cd7ed67b638.tar.gz
rails-b54560600b06112723adf286141a9cd7ed67b638.tar.bz2
rails-b54560600b06112723adf286141a9cd7ed67b638.zip
Have text helpers use built in Regexp.escape rather than home grown alternative
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2350 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb9
1 files changed, 2 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index cafed43aed..732e87078f 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -35,7 +35,7 @@ module ActionView
# N.B.: The +phrase+ is sanitized to include only letters, digits, and spaces before use.
def highlight(text, phrase, highlighter = '<strong class="highlight">\1</strong>')
if phrase.blank? then return text end
- text.gsub(/(#{escape_regexp(phrase)})/i, highlighter) unless text.nil?
+ text.gsub(/(#{Regexp.escape(phrase)})/i, highlighter) unless text.nil?
end
# Extracts an excerpt from the +text+ surrounding the +phrase+ with a number of characters on each side determined
@@ -43,7 +43,7 @@ module ActionView
# excerpt("hello my world", "my", 3) => "...lo my wo..."
def excerpt(text, phrase, radius = 100, excerpt_string = "...")
if text.nil? || phrase.nil? then return end
- phrase = escape_regexp(phrase)
+ phrase = Regexp.escape(phrase)
if found_pos = text =~ /(#{phrase})/i
start_pos = [ found_pos - radius, 0 ].max
@@ -280,11 +280,6 @@ module ActionView
@_cycles[name] = cycle_object
end
- # Returns a version of the text that's safe to use in a regular expression without triggering engine features.
- def escape_regexp(text)
- text.gsub(/([\\|?+*\/\)\(])/) { |m| "\\#{$1}" }
- end
-
AUTO_LINK_RE = /
( # leading text
<\w+.*?>| # leading HTML tag, or