Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix ActiveSupport::Multibyte::Chars#slice for empty strings when star…

…ting offset is negative [#4717 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 265b7c5edfe9b60d1ab547bfef569d94df05b8e9 1 parent 4dbb6e3
Alex Muntean authored josevalim committed
View
3  activesupport/lib/active_support/multibyte/chars.rb
@@ -318,7 +318,8 @@ def slice(*args)
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
View
1  activesupport/test/multibyte_chars_test.rb
@@ -397,6 +397,7 @@ def test_slice_should_take_character_offsets
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)
Please sign in to comment.
Something went wrong with that request. Please try again.