[ruby/yaml] Prefer to use YAML.safe_load

c3d0f64224
This commit is contained in:
Hiroshi SHIBATA 2024-10-16 16:36:34 +09:00
parent 623897c97e
commit d45fb19ee5

View file

@ -55,7 +55,13 @@ class DBM < ::DBM
def fetch( keystr, ifnone = nil )
begin
val = super( keystr )
return YAML.load( val ) if String === val
if String === val
if YAML.respond_to?(:safe_load)
return YAML.safe_load( val )
else
return YAML.load( val )
end
end
rescue IndexError
end
if block_given?
@ -101,7 +107,11 @@ class DBM < ::DBM
def delete( key )
v = super( key )
if String === v
v = YAML.load( v )
if YAML.respond_to?(:safe_load)
v = YAML.safe_load( v )
else
v = YAML.load( v )
end
end
v
end