aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAlex Muntean <amuntean@gilt.com>2010-05-28 13:22:29 +0900
committerJosé Valim <jose.valim@gmail.com>2010-06-30 15:00:55 +0200
commit265b7c5edfe9b60d1ab547bfef569d94df05b8e9 (patch)
treea367011d221f6161cdca88d96413900df55205dc /activesupport
parent4dbb6e3ff001bed14c64af3ddef87b3359a43505 (diff)
downloadrails-265b7c5edfe9b60d1ab547bfef569d94df05b8e9.tar.gz
rails-265b7c5edfe9b60d1ab547bfef569d94df05b8e9.tar.bz2
rails-265b7c5edfe9b60d1ab547bfef569d94df05b8e9.zip
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>
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb3
-rw-r--r--activesupport/test/multibyte_chars_test.rb1
2 files changed, 3 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index 1134d1ccc6..9251b26f62 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -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
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 66aa22ec20..610295fa89 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -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)