diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb | 6 | ||||
-rw-r--r-- | activesupport/test/multibyte_handler_test.rb | 4 |
3 files changed, 8 insertions, 4 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 0154a6d601..9cc032fd04 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make String#chars slicing behaviour consistent with String. Closes #6387 [Manfred Stienstra] + * Pull in latest multibye patch. Closes #6346 [Manfred Stienstra] * Add ActiveSupport::Multibyte. Provides String#chars which lets you deal with strings as a sequence of chars, not of bytes. Closes #6242 [Julian Tarkhanov, Manfred Stienstra, Thijs van der Vossen & Jan Behrens] diff --git a/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb b/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb index c6ef6ad095..6c8eb88702 100644 --- a/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb +++ b/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb @@ -162,10 +162,10 @@ module ActiveSupport::Multibyte::Handlers elsif args[0].kind_of? Range cps = u_unpack(str).slice(*args) cps.nil? ? nil : cps.pack('U*') - elsif args[0].kind_of? Numeric + elsif args.size == 1 && args[0].kind_of?(Numeric) u_unpack(str)[args[0]] else - str.slice(*args) + u_unpack(str).slice(*args).pack('U*') end end alias_method :[], :slice @@ -434,4 +434,4 @@ module ActiveSupport::Multibyte::Handlers UCD = UnicodeDatabase.new end end -end
\ No newline at end of file +end diff --git a/activesupport/test/multibyte_handler_test.rb b/activesupport/test/multibyte_handler_test.rb index 7de3c0001e..06bc904c04 100644 --- a/activesupport/test/multibyte_handler_test.rb +++ b/activesupport/test/multibyte_handler_test.rb @@ -157,6 +157,8 @@ module UTF8HandlingTest assert_equal nil, @handler.slice('', -1..1), "Broken range should return nil" assert_equal '', @handler.slice('', 0..10), "Empty string should not break things" assert_equal "d Блå ffi", @handler.slice(@string, 3..9), "Unicode characters have to be returned" + assert_equal "d Блå ffi", @handler.slice(@string, 3, 7), "Unicode characters have to be returned" + assert_equal "A", @handler.slice(@string, 0, 1), "Slicing from an offset should return characters" assert_equal " Блå ffi ", @handler.slice(@string, 4..10), "Unicode characters have to be returned" assert_equal "", @handler.slice(@string, 7..6), "Range is empty, should return an empty string" assert_raise(ActiveSupport::Multibyte::Handlers::EncodingError) { @handler.slice(@bytestring, 2..3) } @@ -266,4 +268,4 @@ class UTF8HandlingTestPure < Test::Unit::TestCase common_setup @handler = ::ActiveSupport::Multibyte::Handlers::UTF8Handler end -end
\ No newline at end of file +end |