diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-20 16:05:26 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-20 16:05:26 -0600 |
commit | 61e65f606035778367cc52d7d0be190ff00e27ab (patch) | |
tree | 4651bcff93af8b47c56f25509125f1a6d5cbbeb3 /activesupport/lib | |
parent | 1193824994887fb37ca492d7c5eb1f381f2fc220 (diff) | |
parent | b945de3662105abe330cad6e18962ccf7438150b (diff) | |
download | rails-61e65f606035778367cc52d7d0be190ff00e27ab.tar.gz rails-61e65f606035778367cc52d7d0be190ff00e27ab.tar.bz2 rails-61e65f606035778367cc52d7d0be190ff00e27ab.zip |
Merge pull request #20737 from gouravtiwari/multibyte_chars_slice_fix
Fixed multibyte-chars slice! behavior to return nil for out-of-bound
parameters
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/multibyte/chars.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index f6a2e7e949..707cf200b5 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -86,7 +86,8 @@ module ActiveSupport #:nodoc: end # Works like <tt>String#slice!</tt>, but returns an instance of - # Chars, or nil if the string was not modified. + # Chars, or nil if the string was not modified. The string will not be + # modified if the range given is out of bounds # # string = 'Welcome' # string.mb_chars.slice!(3) # => #<ActiveSupport::Multibyte::Chars:0x000000038109b8 @wrapped_string="c"> @@ -94,7 +95,10 @@ 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) + if string_sliced + chars(string_sliced) + end end # Reverses all characters in the string. |