Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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)

Tested against 7187, generated from trunk

  • actionpack/test/template/text_helper_test.rb

    old new  
    5555      "This is a <strong class=\"highlight\">beautiful</strong> morning", 
    5656      highlight("This is a beautiful morning", "beautiful") 
    5757    ) 
     58     
     59    assert_equal( 
     60      "This is a <strong class=\"highlight\">beautiful</strong> morning", 
     61      highlight("This is a beautiful morning", "BEAUTIFUL") 
     62    )   
    5863 
    5964    assert_equal( 
    6065      "This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day", 
     
    7277    ) 
    7378 
    7479    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 
    7593  end 
    7694 
    7795  def test_highlighter_with_regexp 
  • actionpack/lib/action_view/helpers/text_helper.rb

    old new  
    7272        if text.blank? || phrases.blank? 
    7373          text 
    7474        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('|') 
    7686          text.gsub(/(#{match})/i, highlighter) 
    7787        end 
    7888      end