Project

General

Profile

Bug #11209 ยป 0001-Fix-String-when-subclassed.patch

yoongkang (Yoong Kang Lim), 06/04/2015 01:25 AM

View differences:

string.c
1486 1486
    enc = rb_enc_check(str1, str2);
1487 1487
    RSTRING_GETMEM(str1, ptr1, len1);
1488 1488
    RSTRING_GETMEM(str2, ptr2, len2);
1489
    str3 = rb_str_new(0, len1+len2);
1489
    str3 = rb_str_new_with_class(str1, 0, len1+len2);
1490 1490
    ptr3 = RSTRING_PTR(str3);
1491 1491
    memcpy(ptr3, ptr1, len1);
1492 1492
    memcpy(ptr3+len1, ptr2, len2);
test/ruby/test_string.rb
1946 1946
    assert_equal((15..54).to_a.to_a.join, s3)
1947 1947
  end
1948 1948

  
1949
  def test_str_plus_subclassed
1950
    foo = S2.new("foo")
1951
    bar = S2.new("bar")
1952
    baz = foo + bar
1953
    assert_equal(TestString::S2, baz.class)
1954
  end
1955

  
1949 1956
  def test_rb_str_new4
1950 1957
    s = "a" * 100
1951 1958
    s2 = s[10,90]