summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrenGitHub <[email protected]>2025-04-29 06:14:37 +0300
committergit <[email protected]>2025-05-09 17:53:17 +0000
commitae299cc9cd7e19626c973f166098a4128c2779ed (patch)
tree4f899f2a59cc9d07dbf7d84e80ff6bbebd9f5edb
parentf0e2a41d4bacd4ad37843b662194f128737407cf (diff)
[ruby/psych] add first test for safe load stream
https://github.com/ruby/psych/commit/336553b412
-rw-r--r--ext/psych/lib/psych.rb2
-rw-r--r--test/psych/test_stream.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb
index 1c9dea5bba..0c158c9ff3 100644
--- a/ext/psych/lib/psych.rb
+++ b/ext/psych/lib/psych.rb
@@ -671,7 +671,7 @@ module Psych
documents = parse_stream(yaml, filename: filename).children.map do |child|
stream = Psych::Nodes::Stream.new
stream.children << child
- safe_load stream.to_yaml, permitted_classes: permitted_classes, aliases: aliases
+ safe_load(stream.to_yaml, permitted_classes: permitted_classes, aliases: aliases)
end
if block_given?
diff --git a/test/psych/test_stream.rb b/test/psych/test_stream.rb
index 9b71c6d996..ae940d1ee4 100644
--- a/test/psych/test_stream.rb
+++ b/test/psych/test_stream.rb
@@ -54,6 +54,14 @@ module Psych
assert_equal %w{ foo bar }, list
end
+ def test_safe_load_stream_yields_documents
+ list = []
+ Psych.safe_load_stream("--- foo\n...\n--- bar") do |ruby|
+ list << ruby
+ end
+ assert_equal %w{ foo bar }, list
+ end
+
def test_load_stream_break
list = []
Psych.load_stream("--- foo\n...\n--- `") do |ruby|