mirror of
https://github.com/ruby/ruby.git
synced 2025-09-19 10:33:58 +02:00
obj_init_copy
* object.c (rb_obj_init_copy): should check if trusted too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b1ae6e473e
commit
2073258a7d
11 changed files with 58 additions and 27 deletions
|
@ -764,4 +764,36 @@ class TestObject < Test::Unit::TestCase
|
|||
assert_equal((eval("raise #{code}") rescue $!.inspect), out.chomp, bug5473)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_not_initialize_copy
|
||||
a = yield
|
||||
b = yield
|
||||
assert_nothing_raised("copy") {a.instance_eval {initialize_copy(b)}}
|
||||
c = a.dup.freeze
|
||||
assert_raise(RuntimeError, "frozen") {c.instance_eval {initialize_copy(b)}}
|
||||
d = a.dup.trust
|
||||
assert_raise(SecurityError, "untrust") do
|
||||
proc {
|
||||
$SAFE = 4
|
||||
d.instance_eval {initialize_copy(b)}
|
||||
}.call
|
||||
end
|
||||
[a, b, c, d]
|
||||
end
|
||||
|
||||
def test_bad_initialize_copy
|
||||
assert_not_initialize_copy {Object.new}
|
||||
assert_not_initialize_copy {[].to_enum}
|
||||
assert_not_initialize_copy {Enumerator::Generator.new {}}
|
||||
assert_not_initialize_copy {Enumerator::Yielder.new {}}
|
||||
assert_not_initialize_copy {File.stat(__FILE__)}
|
||||
assert_not_initialize_copy {open(__FILE__)}.each(&:close)
|
||||
assert_not_initialize_copy {ARGF.class.new}
|
||||
assert_not_initialize_copy {Random.new}
|
||||
assert_not_initialize_copy {//}
|
||||
assert_not_initialize_copy {/.*/.match("foo")}
|
||||
st = Struct.new(:foo)
|
||||
assert_not_initialize_copy {st.new}
|
||||
assert_not_initialize_copy {Time.now}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue