[ruby/yaml] Also use safe_load with each_value, values and shift
https://github.com/ruby/yaml/commit/f47d6123eb
This commit is contained in:
parent
d45fb19ee5
commit
1d7547f50d
@ -158,7 +158,7 @@ class DBM < ::DBM
|
|||||||
#
|
#
|
||||||
# Returns +self+.
|
# Returns +self+.
|
||||||
def each_value # :yields: value
|
def each_value # :yields: value
|
||||||
super { |v| yield YAML.load( v ) }
|
super { |v| yield YAML.respond_to?(:safe_load) ? YAML.safe_load( v ) : YAML.load( v ) }
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ class DBM < ::DBM
|
|||||||
#
|
#
|
||||||
# Returns an array of values from the database.
|
# Returns an array of values from the database.
|
||||||
def values
|
def values
|
||||||
super.collect { |v| YAML.load( v ) }
|
super.collect { |v| YAML.respond_to?(:safe_load) ? YAML.safe_load( v ) : YAML.load( v ) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# :call-seq:
|
# :call-seq:
|
||||||
@ -213,7 +213,9 @@ class DBM < ::DBM
|
|||||||
# The order in which values are removed/returned is not guaranteed.
|
# The order in which values are removed/returned is not guaranteed.
|
||||||
def shift
|
def shift
|
||||||
a = super
|
a = super
|
||||||
a[1] = YAML.load( a[1] ) if a
|
if a
|
||||||
|
a[1] = YAML.respond_to?(:safe_load) ? YAML.safe_load( a[1] ) : YAML.load( a[1] )
|
||||||
|
end
|
||||||
a
|
a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,4 +22,25 @@ class TestYAMLDBM < Test::Unit::TestCase
|
|||||||
assert_equal "value", @dbm.delete("key")
|
assert_equal "value", @dbm.delete("key")
|
||||||
assert_nil @dbm["key"]
|
assert_nil @dbm["key"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_each_value
|
||||||
|
@dbm["key1"] = "value1"
|
||||||
|
@dbm["key2"] = "value2"
|
||||||
|
@dbm.each_value do |value|
|
||||||
|
assert_match(/value[12]/, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_values
|
||||||
|
@dbm["key1"] = "value1"
|
||||||
|
@dbm["key2"] = "value2"
|
||||||
|
@dbm.values.each do |value|
|
||||||
|
assert_match(/value[12]/, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_shift
|
||||||
|
@dbm["key"] = "value"
|
||||||
|
assert_equal ["key", "value"], @dbm.shift
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user