From 41c362352433f265a95c00d8e7b5c1f1299e9011 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Thu, 12 Oct 2006 21:13:05 +0000 Subject: Use String#chars in TextHelper::excerpt. Closes #6386 [Manfred Stienstra] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5288 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/text_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 27e093a1c3..0e142cbaff 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -45,14 +45,14 @@ module ActionView if text.nil? || phrase.nil? then return end phrase = Regexp.escape(phrase) - if found_pos = text =~ /(#{phrase})/i + if found_pos = text.chars =~ /(#{phrase})/i start_pos = [ found_pos - radius, 0 ].max - end_pos = [ found_pos + phrase.length + radius, text.length ].min + end_pos = [ found_pos + phrase.chars.length + radius, text.chars.length ].min prefix = start_pos > 0 ? excerpt_string : "" - postfix = end_pos < text.length ? excerpt_string : "" + postfix = end_pos < text.chars.length ? excerpt_string : "" - prefix + text[start_pos..end_pos].strip + postfix + prefix + text.chars[start_pos..end_pos].strip + postfix else nil end -- cgit v1.2.3