Revision 1709
Added by Jean-Philippe Lang almost 17 years ago
trunk/app/helpers/search_helper.rb | ||
---|---|---|
18 | 18 |
module SearchHelper |
19 | 19 |
def highlight_tokens(text, tokens) |
20 | 20 |
return text unless text && tokens && !tokens.empty? |
21 |
regexp = Regexp.new "(#{tokens.join('|')})", Regexp::IGNORECASE |
|
21 |
re_tokens = tokens.collect {|t| Regexp.escape(t)} |
|
22 |
regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE |
|
22 | 23 |
result = '' |
23 | 24 |
text.split(regexp).each_with_index do |words, i| |
24 | 25 |
if result.length > 1200 |
Also available in: Unified diff
Fixed: tokens not escaped in highlight_tokens regexp (#1702).