mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix chars.reverse for multibyte decomposed strings
[#597 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
parent
e93c2da141
commit
2378085023
2 changed files with 12 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue