summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2020-11-12 11:04:06 -0500
committerMarc-Andre Lafortune <github@marc-andre.ca>2020-11-12 11:07:36 -0500
commit0210e310d04cbc9b236ccdde6caaf79aab4eb794 (patch)
tree23b545e39d29ae7740f2f625a3a8ef3d2e375304 /test
parent67ecafb0e2aed5974adff45280080eab1e25656d (diff)
downloadpsych-0210e310d04cbc9b236ccdde6caaf79aab4eb794.zip
Add `Psych.safe_load_file`. Tweak doc to provide `safe_` examples.
Diffstat (limited to 'test')
-rw-r--r--test/psych/test_exception.rb12
-rw-r--r--test/psych/test_psych.rb12
2 files changed, 24 insertions, 0 deletions
diff --git a/test/psych/test_exception.rb b/test/psych/test_exception.rb
index e355c26..78601d0 100644
--- a/test/psych/test_exception.rb
+++ b/test/psych/test_exception.rb
@@ -118,6 +118,18 @@ module Psych
}
end
+ def test_safe_load_file_exception
+ Tempfile.create(['loadfile', 'yml']) {|t|
+ t.binmode
+ t.write '--- `'
+ t.close
+ ex = assert_raises(Psych::SyntaxError) do
+ Psych.safe_load_file t.path
+ end
+ assert_equal t.path, ex.file
+ }
+ end
+
def test_psych_parse_takes_file
ex = assert_raises(Psych::SyntaxError) do
Psych.parse '--- `'
diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb
index 7219e83..30612de 100644
--- a/test/psych/test_psych.rb
+++ b/test/psych/test_psych.rb
@@ -319,6 +319,18 @@ class TestPsych < Psych::TestCase
}
end
+ def test_safe_load_file_with_permitted_classe
+ Tempfile.create(['false', 'yml']) {|t|
+ t.binmode
+ t.write("--- !ruby/range\nbegin: 0\nend: 42\nexcl: false\n")
+ t.close
+ assert_equal 0..42, Psych.safe_load_file(t.path, permitted_classes: [Range])
+ assert_raises(Psych::DisallowedClass) {
+ Psych.safe_load_file(t.path)
+ }
+ }
+ end
+
def test_parse_file
Tempfile.create(['yikes', 'yml']) {|t|
t.binmode