From b5c3987294d3860a78b1b04ee49b2b55f3cdc614 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Thu, 10 Nov 2011 11:26:42 +0400 Subject: Fix and simplify highlight regexp --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- actionpack/test/template/text_helper_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 21074efe86..bc8572fe69 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -120,7 +120,7 @@ module ActionView text else match = Array(phrases).map { |p| Regexp.escape(p) }.join('|') - text.gsub(/(#{match})(?!(?:[^<]*?)(?:["'])[^<>]*>)/i, options[:highlighter]) + text.gsub(/(#{match})(?![^<]*?>)/i, options[:highlighter]) end.html_safe end diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 02f9609483..a0afb77f05 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -194,6 +194,10 @@ class TextHelperTest < ActionView::TestCase "

This is a beautiful morning, but also a beautiful day

", highlight("

This is a beautiful morning, but also a beautiful day

", "beautiful") ) + assert_equal( + "
abc div
", + highlight("
abc div
", "div", :highlighter => '\1') + ) end def test_excerpt -- cgit v1.2.3