aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMatias Flores <mflores@atlanware.com>2009-09-26 21:32:21 -0300
committerJeremy Kemper <jeremy@bitsweat.net>2009-11-02 17:57:55 -0800
commit23780850237876cf81038534d8f59fa307af0b31 (patch)
tree3865b6755f66be53270ae29e1a06865ae9cd2d0f /activesupport
parente93c2da14108c324ddf5f08f0165b342e028896f (diff)
downloadrails-23780850237876cf81038534d8f59fa307af0b31.tar.gz
rails-23780850237876cf81038534d8f59fa307af0b31.tar.bz2
rails-23780850237876cf81038534d8f59fa307af0b31.zip
Fix chars.reverse for multibyte decomposed strings
[#597 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb2
-rw-r--r--activesupport/test/multibyte_chars_test.rb11
2 files changed, 12 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index 579ccc124d..c9bcfbd313 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -321,7 +321,7 @@ module ActiveSupport #:nodoc:
# Example:
# 'Café'.mb_chars.reverse.to_s #=> 'éfaC'
def reverse
- chars(self.class.u_unpack(@wrapped_string).reverse.pack('U*'))
+ chars(self.class.g_unpack(@wrapped_string).reverse.flatten.pack('U*'))
end
# Implements Unicode-aware slice with codepoints. Slicing on one point returns the codepoints for that
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 0d3c3c7716..a1ea8c8f4c 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -384,6 +384,17 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
assert_equal 'わちにこ', @chars.reverse
end
+ def test_reverse_should_work_with_normalized_strings
+ str = 'bös'
+ reversed_str = 'söb'
+ assert_equal chars(reversed_str).normalize(:kc), chars(str).normalize(:kc).reverse
+ assert_equal chars(reversed_str).normalize(:c), chars(str).normalize(:c).reverse
+ assert_equal chars(reversed_str).normalize(:d), chars(str).normalize(:d).reverse
+ assert_equal chars(reversed_str).normalize(:kd), chars(str).normalize(:kd).reverse
+ assert_equal chars(reversed_str).decompose, chars(str).decompose.reverse
+ assert_equal chars(reversed_str).compose, chars(str).compose.reverse
+ end
+
def test_slice_should_take_character_offsets
assert_equal nil, ''.mb_chars.slice(0)
assert_equal 'こ', @chars.slice(0)