Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix AS::MB::Chars#+ to not alter self [#4646 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 16cef77d37ffe3e2cdc6f7db76b4ae59ce4cbc5b 1 parent 13a3690
@jamesmacaulay jamesmacaulay authored josevalim committed
View
2  activesupport/lib/active_support/multibyte/chars.rb
@@ -105,7 +105,7 @@ def self.wants?(string)
# Example:
# ('Café'.mb_chars + ' périferôl').to_s #=> "Café périferôl"
def +(other)
- self << other
+ chars(@wrapped_string + other)
end
# Like <tt>String#=~</tt> only it returns the character offset (in codepoints) instead of the byte offset.
View
16 activesupport/test/multibyte_chars_test.rb
@@ -49,13 +49,15 @@ def test_forwarded_method_with_non_string_result_should_be_returned_vertabim
end
def test_should_concatenate
- assert_equal 'ab', 'a'.mb_chars + 'b'
- assert_equal 'ab', 'a' + 'b'.mb_chars
- assert_equal 'ab', 'a'.mb_chars + 'b'.mb_chars
-
- assert_equal 'ab', 'a'.mb_chars << 'b'
- assert_equal 'ab', 'a' << 'b'.mb_chars
- assert_equal 'ab', 'a'.mb_chars << 'b'.mb_chars
+ mb_a = 'a'.mb_chars
+ mb_b = 'b'.mb_chars
+ assert_equal 'ab', mb_a + 'b'
+ assert_equal 'ab', 'a' + mb_b
+ assert_equal 'ab', mb_a + mb_b
+
+ assert_equal 'ab', mb_a << 'b'
+ assert_equal 'ab', 'a' << mb_b
+ assert_equal 'abb', mb_a << mb_b
end
def test_consumes_utf8_strings
Please sign in to comment.
Something went wrong with that request. Please try again.