Permalink
Browse files

Fix chars.reverse for multibyte decomposed strings

[#597 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent 7ba8025 commit 4ae03b2d5a7b81a8b8d330c12de40f970525a67a @matflores matflores committed with jeremy Sep 27, 2009
Showing with 12 additions and 1 deletion.
  1. +1 −1 activesupport/lib/active_support/multibyte/chars.rb
  2. +11 −0 activesupport/test/multibyte_chars_test.rb
@@ -320,7 +320,7 @@ def size
# 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
@@ -379,6 +379,17 @@ def test_reverse_reverses_characters
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)

0 comments on commit 4ae03b2

Please sign in to comment.