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
return ST_STOP;
}
else {
if (STR_SHARED_P(str)) { /* str should not be shared */
if (STR_SHARED_P(str) || /* str should not be shared */
FL_TEST_RAW(str, FL_EXIVAR) || /* no instance variables */
(RBASIC_CLASS(str) && RBASIC_CLASS(str) != rb_cString)) { /* no singleton */
const int taint = RBASIC(str)->flags & FL_TAINT;
str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), STR_ENC_GET(str));
RBASIC(str)->flags |= FL_FREEZE | taint;
test/-ext-/string/test_fstring.rb
assert_predicate(str, :tainted?)
assert_predicate(fstr, :tainted?)
end
def test_instance_variable
str = __method__.to_s.capitalize
str.instance_variable_set(:@test, 42)
str.freeze
fstr = Bug::String.fstring(str)
assert_send([str, :instance_variable_defined?, :@test])
assert_not_send([fstr, :instance_variable_defined?, :@test])
end
def test_singleton_method
str = __method__.to_s.capitalize
def str.foo
end
str.freeze
fstr = Bug::String.fstring(str)
assert_send([str, :respond_to?, :foo])
assert_not_send([fstr, :respond_to?, :foo])
end
class S < String
end
def test_subclass
str = S.new(__method__.to_s.capitalize)
str.freeze
fstr = Bug::String.fstring(str)
assert_instance_of(S, str)
assert_instance_of(String, fstr)
end
end
(3-3/3)