Project

General

Profile

Bug #11386 ยป 0003-string.c-bare-string-fstring.patch

nobu (Nobuyoshi Nakada), 07/23/2015 01:42 AM

View differences:

string.c
245 245
	return ST_STOP;
246 246
    }
247 247
    else {
248
	if (STR_SHARED_P(str)) { /* str should not be shared */
248
	if (STR_SHARED_P(str) || /* str should not be shared */
249
	    FL_TEST_RAW(str, FL_EXIVAR) || /* no instance variables */
250
	    (RBASIC_CLASS(str) && RBASIC_CLASS(str) != rb_cString)) { /* no singleton */
249 251
	    const int taint = RBASIC(str)->flags & FL_TAINT;
250 252
	    str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), STR_ENC_GET(str));
251 253
	    RBASIC(str)->flags |= FL_FREEZE | taint;
test/-ext-/string/test_fstring.rb
43 43
    assert_predicate(str, :tainted?)
44 44
    assert_predicate(fstr, :tainted?)
45 45
  end
46

  
47
  def test_instance_variable
48
    str = __method__.to_s.capitalize
49
    str.instance_variable_set(:@test, 42)
50
    str.freeze
51
    fstr = Bug::String.fstring(str)
52
    assert_send([str, :instance_variable_defined?, :@test])
53
    assert_not_send([fstr, :instance_variable_defined?, :@test])
54
  end
55

  
56
  def test_singleton_method
57
    str = __method__.to_s.capitalize
58
    def str.foo
59
    end
60
    str.freeze
61
    fstr = Bug::String.fstring(str)
62
    assert_send([str, :respond_to?, :foo])
63
    assert_not_send([fstr, :respond_to?, :foo])
64
  end
65

  
66
  class S < String
67
  end
68

  
69
  def test_subclass
70
    str = S.new(__method__.to_s.capitalize)
71
    str.freeze
72
    fstr = Bug::String.fstring(str)
73
    assert_instance_of(S, str)
74
    assert_instance_of(String, fstr)
75
  end
46 76
end