diff options
author | Hiroshi SHIBATA <[email protected]> | 2024-10-16 16:45:49 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-10-16 17:04:36 +0900 |
commit | 1d7547f50d1187f49b5cfec627425e657cdaf9af (patch) | |
tree | 97624c5b4b4e4a6760d575c408e81e29d7d57596 | |
parent | d45fb19ee579eb8b28e4dd565bf21c0044ceb326 (diff) |
[ruby/yaml] Also use safe_load with each_value, values and shift
https://github.com/ruby/yaml/commit/f47d6123eb
-rw-r--r-- | lib/yaml/dbm.rb | 8 | ||||
-rw-r--r-- | test/yaml/test_dbm.rb | 21 |
2 files changed, 26 insertions, 3 deletions
diff --git a/lib/yaml/dbm.rb b/lib/yaml/dbm.rb index 167799bcd4..126d72dd4d 100644 --- a/lib/yaml/dbm.rb +++ b/lib/yaml/dbm.rb @@ -158,7 +158,7 @@ class DBM < ::DBM # # Returns +self+. 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 end @@ -167,7 +167,7 @@ class DBM < ::DBM # # Returns an array of values from the database. def values - super.collect { |v| YAML.load( v ) } + super.collect { |v| YAML.respond_to?(:safe_load) ? YAML.safe_load( v ) : YAML.load( v ) } end # :call-seq: @@ -213,7 +213,9 @@ class DBM < ::DBM # The order in which values are removed/returned is not guaranteed. def shift 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 end diff --git a/test/yaml/test_dbm.rb b/test/yaml/test_dbm.rb index c90b46a263..15d441d23b 100644 --- a/test/yaml/test_dbm.rb +++ b/test/yaml/test_dbm.rb @@ -22,4 +22,25 @@ class TestYAMLDBM < Test::Unit::TestCase assert_equal "value", @dbm.delete("key") assert_nil @dbm["key"] 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
\ No newline at end of file |