diff options
-rw-r--r-- | activesupport/lib/active_support/multibyte/chars.rb | 3 | ||||
-rw-r--r-- | activesupport/test/multibyte_chars_test.rb | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index f6a2e7e949..a76692ec4b 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -94,7 +94,8 @@ module ActiveSupport #:nodoc: # string.mb_chars.slice!(0..3) # => #<ActiveSupport::Multibyte::Chars:0x00000002eb80a0 @wrapped_string="Welo"> # string # => 'me' def slice!(*args) - chars(@wrapped_string.slice!(*args)) + string_sliced = @wrapped_string.slice!(*args) + string_sliced ? chars(string_sliced) : nil end # Reverses all characters in the string. diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index e1c4b705f8..42829c6a8e 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -413,6 +413,10 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase assert_equal 'にち', @chars.slice!(1..2) end + def test_slice_bang_returns_nil_on_out_of_bound_arguments + assert_equal nil, @chars.mb_chars.slice!(9..10) + end + def test_slice_bang_removes_the_slice_from_the_receiver chars = 'úüù'.mb_chars chars.slice!(0,2) |