Revision
3827
Author
vincent.isambart@gmail.com
Date
2010-03-19 04:35:23 -0700 (Fri, 19 Mar 2010)

Log Message

Fixed a bug in String#+

Modified Paths

Diff

Modified: MacRuby/trunk/string.c (3826 => 3827)


--- MacRuby/trunk/string.c	2010-03-19 05:13:51 UTC (rev 3826)
+++ MacRuby/trunk/string.c	2010-03-19 11:35:23 UTC (rev 3827)
@@ -2005,7 +2005,17 @@
 rstr_plus(VALUE self, SEL sel, VALUE other)
 {
     rb_str_t *newstr = str_dup(RSTR(self));
-    str_concat_string(newstr, str_need_string(other));
+    rb_str_t *otherstr = str_need_string(other);
+    // if other cannot be concatenated to self
+    // but self is ASCII-only and the encodings of both string are ASCII-compatible
+    // then the new string takes the encoding of other
+    if ((str_compatible_encoding(newstr, otherstr) == NULL)
+	    && newstr->encoding->ascii_compatible
+	    && otherstr->encoding->ascii_compatible
+	    && str_is_ruby_ascii_only(newstr)) {
+	newstr->encoding = otherstr->encoding;
+    }
+    str_concat_string(newstr, otherstr);
     if (OBJ_TAINTED(self) || OBJ_TAINTED(other)) {
 	OBJ_TAINT(newstr);
     }