aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-11-10 02:53:43 -0800
committerJosé Valim <jose.valim@gmail.com>2011-11-10 02:53:43 -0800
commitbdd76fb5e397768f9fca78ef6926afcf1ba71365 (patch)
tree470f15aefdfeb42c2dd274f577a522846c5eca57
parent909e5cc32d0bd47dad2f5c5404670a074a9dabbd (diff)
parentb5c3987294d3860a78b1b04ee49b2b55f3cdc614 (diff)
downloadrails-bdd76fb5e397768f9fca78ef6926afcf1ba71365.tar.gz
rails-bdd76fb5e397768f9fca78ef6926afcf1ba71365.tar.bz2
rails-bdd76fb5e397768f9fca78ef6926afcf1ba71365.zip
Merge pull request #3592 from avakhov/av-highlight-regexp
Fix and simplify highlight regexp
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb2
-rw-r--r--actionpack/test/template/text_helper_test.rb4
2 files changed, 5 insertions, 1 deletions
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
"<p>This is a <strong class=\"highlight\">beautiful</strong> <a href=\"http://example.com/beautiful#top?what=beautiful%20morning&amp;when=now+then\">morning</a>, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
highlight("<p>This is a beautiful <a href=\"http://example.com/beautiful\#top?what=beautiful%20morning&when=now+then\">morning</a>, but also a beautiful day</p>", "beautiful")
)
+ assert_equal(
+ "<div>abc <b>div</b></div>",
+ highlight("<div>abc div</div>", "div", :highlighter => '<b>\1</b>')
+ )
end
def test_excerpt