1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test/ostruct/test_ostruct.rb: Use YAML.unsafe_load instead of YAML.load

Follow-up of fbb4e3f96c
This commit is contained in:
Yusuke Endoh 2021-05-17 11:36:16 +09:00
parent 42b20bdbfe
commit da5b283963

View file

@ -357,18 +357,18 @@ class TC_OpenStruct < Test::Unit::TestCase
def test_legacy_yaml
s = "--- !ruby/object:OpenStruct\ntable:\n :foo: 42\n"
o = YAML.load(s)
o = YAML.unsafe_load(s)
assert_equal(42, o.foo)
o = OpenStruct.new(table: {foo: 42})
assert_equal({foo: 42}, YAML.load(YAML.dump(o)).table)
assert_equal({foo: 42}, YAML.unsafe_load(YAML.dump(o)).table)
end
def test_yaml
h = {name: "John Smith", age: 70, pension: 300.42}
yaml = "--- !ruby/object:OpenStruct\nname: John Smith\nage: 70\npension: 300.42\n"
os1 = OpenStruct.new(h)
os2 = YAML.load(os1.to_yaml)
os2 = YAML.unsafe_load(os1.to_yaml)
assert_equal yaml, os1.to_yaml
assert_equal os1, os2
assert_equal true, os1.eql?(os2)