mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix ActiveSupport::Multibyte::Chars#slice for empty strings when starting offset is negative [#4717 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
4dbb6e3ff0
commit
265b7c5edf
2 changed files with 3 additions and 1 deletions
|
@ -318,7 +318,8 @@ module ActiveSupport #:nodoc:
|
|||
character = Unicode.u_unpack(@wrapped_string)[args[0]]
|
||||
result = character.nil? ? nil : [character].pack('U')
|
||||
else
|
||||
result = Unicode.u_unpack(@wrapped_string).slice(*args).pack('U*')
|
||||
cps = Unicode.u_unpack(@wrapped_string).slice(*args)
|
||||
result = cps.nil? ? nil : cps.pack('U*')
|
||||
end
|
||||
result.nil? ? nil : chars(result)
|
||||
end
|
||||
|
|
|
@ -397,6 +397,7 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
|
|||
assert_equal 'こ', @chars.slice(0)
|
||||
assert_equal 'わ', @chars.slice(3)
|
||||
assert_equal nil, ''.mb_chars.slice(-1..1)
|
||||
assert_equal nil, ''.mb_chars.slice(-1, 1)
|
||||
assert_equal '', ''.mb_chars.slice(0..10)
|
||||
assert_equal 'にちわ', @chars.slice(1..3)
|
||||
assert_equal 'にちわ', @chars.slice(1, 3)
|
||||
|
|
Loading…
Reference in a new issue