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

Ticket #9646: fix_for_slicing_by_regexp.20071015.diff

File fix_for_slicing_by_regexp.20071015.diff, 2.1 kB (added by yob, 1 year ago)
  • activesupport/test/multibyte_handler_test.rb

    old new  
    160160    assert_equal "d Блå ffi", @handler.slice(@string, 3, 7), "Unicode characters have to be returned" 
    161161    assert_equal "A", @handler.slice(@string, 0, 1), "Slicing from an offset should return characters" 
    162162    assert_equal " Блå ffi ", @handler.slice(@string, 4..10), "Unicode characters have to be returned" 
     163    assert_equal "ffi бла", @handler.slice(@string, /ffi бла/u), "Slicing on Regexps should be supported" 
     164    assert_equal "ffi бла", @handler.slice(@string, /ffi \w\wа/u), "Slicing on Regexps should be supported" 
     165    assert_equal nil, @handler.slice(@string, /unknown/u), "Slicing on Regexps with no match should return nil" 
     166    assert_equal "ffi бла", @handler.slice(@string, /(ffi бла)/u,1), "Slicing on Regexps with a match group should be supported" 
     167    assert_equal nil, @handler.slice(@string, /(ffi)/u,2), "Slicing with a Regexp and asking for an invalid match group should return nil" 
    163168    assert_equal "", @handler.slice(@string, 7..6), "Range is empty, should return an empty string" 
    164169    assert_raise(ActiveSupport::Multibyte::Handlers::EncodingError) { @handler.slice(@bytestring, 2..3) } 
    165170    assert_raise(TypeError, "With 2 args, should raise TypeError for non-Numeric or Regexp first argument") { @handler.slice(@string, 2..3, 1) } 
  • activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb

    old new  
    255255        elsif args[0].kind_of? Range 
    256256          cps = u_unpack(str).slice(*args) 
    257257          cps.nil? ? nil : cps.pack('U*') 
     258        elsif args[0].kind_of? Regexp 
     259          str.slice(*args) 
    258260        elsif args.size == 1 && args[0].kind_of?(Numeric) 
    259261          u_unpack(str)[args[0]] 
    260262        else