mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix and simplify highlight regexp
This commit is contained in:
parent
a625523e75
commit
b5c3987294
2 changed files with 5 additions and 1 deletions
|
@ -120,7 +120,7 @@ module ActionView
|
||||||
text
|
text
|
||||||
else
|
else
|
||||||
match = Array(phrases).map { |p| Regexp.escape(p) }.join('|')
|
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.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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&when=now+then\">morning</a>, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
|
"<p>This is a <strong class=\"highlight\">beautiful</strong> <a href=\"http://example.com/beautiful#top?what=beautiful%20morning&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")
|
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
|
end
|
||||||
|
|
||||||
def test_excerpt
|
def test_excerpt
|
||||||
|
|
Loading…
Reference in a new issue