summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrenGitHub <[email protected]>2025-04-28 21:47:14 +0300
committergit <[email protected]>2025-05-09 17:53:17 +0000
commitd69319304f111a9c1c9fac8d92460547b8749610 (patch)
treeaadf057f93706444e7458ce983a904dbea5f26da
parent011982ef837150044d9f18acc49a7b70e39eaf76 (diff)
[ruby/psych] Add safe version for load_stream
https://github.com/ruby/psych/commit/30a2a5ee94
-rw-r--r--ext/psych/lib/psych.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb
index d7567d87e9..64637b97f7 100644
--- a/ext/psych/lib/psych.rb
+++ b/ext/psych/lib/psych.rb
@@ -654,6 +654,26 @@ module Psych
end
###
+ # Load multiple documents given in +yaml+. Returns the parsed documents
+ # as a list.
+ #
+ # Example:
+ #
+ # Psych.safe_load_stream("--- foo\n...\n--- bar\n...") # => ['foo', 'bar']
+ #
+ # list = []
+ # Psych.safe_load_stream("--- foo\n...\n--- bar\n...") do |ruby|
+ # list << ruby
+ # end
+ # list # => ['foo', 'bar']
+ #
+ def self.safe_load_stream yaml, filename: nil, permitted_classes: [], aliases: false
+ parse_stream(yaml, filename: filename).children.map do |child|
+ safe_load(child.to_yaml, permitted_classes, aliases: aliases)
+ end
+ end
+
+ ###
# Load the document contained in +filename+. Returns the yaml contained in
# +filename+ as a Ruby object, or if the file is empty, it returns
# the specified +fallback+ return value, which defaults to +false+.