Ticket #7400: make_highlight_helper_multibyte_safe.5.patch
| File make_highlight_helper_multibyte_safe.5.patch, 2.3 kB (added by norbert, 1 year ago) |
|---|
-
actionpack/test/template/text_helper_test.rb
old new 55 55 "This is a <strong class=\"highlight\">beautiful</strong> morning", 56 56 highlight("This is a beautiful morning", "beautiful") 57 57 ) 58 59 assert_equal( 60 "This is a <strong class=\"highlight\">beautiful</strong> morning", 61 highlight("This is a beautiful morning", "BEAUTIFUL") 62 ) 58 63 59 64 assert_equal( 60 65 "This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day", … … 72 77 ) 73 78 74 79 assert_equal ' ', highlight(' ', 'blank text is returned verbatim') 80 81 82 with_kcode 'u' do 83 assert_equal( 84 "Saisissez directement votre <strong class=\"highlight\">région</strong> une autre <strong class=\"highlight\">région</strong>âŠ", 85 highlight("Saisissez directement votre région une autre régionâŠ", "région") 86 ) 87 88 assert_equal( 89 "Saisissez directement votre <strong class=\"highlight\">région</strong> une autre <strong class=\"highlight\">région</strong>âŠ", 90 highlight("Saisissez directement votre région une autre régionâŠ", "RÃGION") 91 ) 92 end 75 93 end 76 94 77 95 def test_highlighter_with_regexp -
actionpack/lib/action_view/helpers/text_helper.rb
old new 72 72 if text.blank? || phrases.blank? 73 73 text 74 74 else 75 match = Array(phrases).map { |p| Regexp.escape(p) }.join('|') 75 match = Array(phrases).map do |p| 76 p.split(//u).map do |x| 77 if x.length > 1 78 uc = x.chars.upcase 79 dc = x.chars.downcase 80 uc == dc ? Regexp.escape(x) : "[#{uc}#{dc}]" 81 else 82 Regexp.escape(x) 83 end 84 end.join 85 end.join('|') 76 86 text.gsub(/(#{match})/i, highlighter) 77 87 end 78 88 end