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 160 160 assert_equal "d Ðлå ï¬", @handler.slice(@string, 3, 7), "Unicode characters have to be returned" 161 161 assert_equal "A", @handler.slice(@string, 0, 1), "Slicing from an offset should return characters" 162 162 assert_equal " Ðлå ï¬ ", @handler.slice(@string, 4..10), "Unicode characters have to be returned" 163 assert_equal "ï¬ Ð±Ð»Ð°", @handler.slice(@string, /ï¬ Ð±Ð»Ð°/u), "Slicing on Regexps should be supported" 164 assert_equal "ï¬ Ð±Ð»Ð°", @handler.slice(@string, /ï¬ \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 "ï¬ Ð±Ð»Ð°", @handler.slice(@string, /(ï¬ Ð±Ð»Ð°)/u,1), "Slicing on Regexps with a match group should be supported" 167 assert_equal nil, @handler.slice(@string, /(ï¬)/u,2), "Slicing with a Regexp and asking for an invalid match group should return nil" 163 168 assert_equal "", @handler.slice(@string, 7..6), "Range is empty, should return an empty string" 164 169 assert_raise(ActiveSupport::Multibyte::Handlers::EncodingError) { @handler.slice(@bytestring, 2..3) } 165 170 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 255 255 elsif args[0].kind_of? Range 256 256 cps = u_unpack(str).slice(*args) 257 257 cps.nil? ? nil : cps.pack('U*') 258 elsif args[0].kind_of? Regexp 259 str.slice(*args) 258 260 elsif args.size == 1 && args[0].kind_of?(Numeric) 259 261 u_unpack(str)[args[0]] 260 262 else