@@ -249,11 +249,11 @@ module Psych
249
249
#
250
250
# Example:
251
251
#
252
- # Psych.load ("--- a") # => 'a'
253
- # Psych.load ("---\n - a\n - b") # => ['a', 'b']
252
+ # Psych.unsafe_load ("--- a") # => 'a'
253
+ # Psych.unsafe_load ("---\n - a\n - b") # => ['a', 'b']
254
254
#
255
255
# begin
256
- # Psych.load ("--- `", filename: "file.txt")
256
+ # Psych.unsafe_load ("--- `", filename: "file.txt")
257
257
# rescue Psych::SyntaxError => ex
258
258
# ex.file # => 'file.txt'
259
259
# ex.message # => "(file.txt): found character that cannot start any token"
@@ -262,14 +262,14 @@ module Psych
262
262
# When the optional +symbolize_names+ keyword argument is set to a
263
263
# true value, returns symbols for keys in Hash objects (default: strings).
264
264
#
265
- # Psych.load ("---\n foo: bar") # => {"foo"=>"bar"}
266
- # Psych.load ("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
265
+ # Psych.unsafe_load ("---\n foo: bar") # => {"foo"=>"bar"}
266
+ # Psych.unsafe_load ("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
267
267
#
268
268
# Raises a TypeError when `yaml` parameter is NilClass
269
269
#
270
270
# NOTE: This method *should not* be used to parse untrusted documents, such as
271
271
# YAML documents that are supplied via user input. Instead, please use the
272
- # safe_load method.
272
+ # load method or the safe_load method.
273
273
#
274
274
def self . unsafe_load yaml , legacy_filename = NOT_GIVEN , filename : nil , fallback : false , symbolize_names : false , freeze : false
275
275
if legacy_filename != NOT_GIVEN
@@ -363,6 +363,46 @@ def self.safe_load yaml, legacy_permitted_classes = NOT_GIVEN, legacy_permitted_
363
363
result
364
364
end
365
365
366
+ ###
367
+ # Load +yaml+ in to a Ruby data structure. If multiple documents are
368
+ # provided, the object contained in the first document will be returned.
369
+ # +filename+ will be used in the exception message if any exception
370
+ # is raised while parsing. If +yaml+ is empty, it returns
371
+ # the specified +fallback+ return value, which defaults to +false+.
372
+ #
373
+ # Raises a Psych::SyntaxError when a YAML syntax error is detected.
374
+ #
375
+ # Example:
376
+ #
377
+ # Psych.load("--- a") # => 'a'
378
+ # Psych.load("---\n - a\n - b") # => ['a', 'b']
379
+ #
380
+ # begin
381
+ # Psych.load("--- `", filename: "file.txt")
382
+ # rescue Psych::SyntaxError => ex
383
+ # ex.file # => 'file.txt'
384
+ # ex.message # => "(file.txt): found character that cannot start any token"
385
+ # end
386
+ #
387
+ # When the optional +symbolize_names+ keyword argument is set to a
388
+ # true value, returns symbols for keys in Hash objects (default: strings).
389
+ #
390
+ # Psych.load("---\n foo: bar") # => {"foo"=>"bar"}
391
+ # Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
392
+ #
393
+ # Raises a TypeError when `yaml` parameter is NilClass. This method is
394
+ # similar to `safe_load` except that `Symbol` objects are allowed by default.
395
+ #
396
+ def self . load yaml , permitted_classes : [ Symbol ] , permitted_symbols : [ ] , aliases : false , filename : nil , fallback : nil , symbolize_names : false , freeze : false
397
+ safe_load yaml , permitted_classes : permitted_classes ,
398
+ permitted_symbols : permitted_symbols ,
399
+ aliases : aliases ,
400
+ filename : filename ,
401
+ fallback : fallback ,
402
+ symbolize_names : symbolize_names ,
403
+ freeze : freeze
404
+ end
405
+
366
406
###
367
407
# Parse a YAML string in +yaml+. Returns the Psych::Nodes::Document.
368
408
# +filename+ is used in the exception message if a Psych::SyntaxError is
@@ -595,6 +635,7 @@ def self.safe_load_file filename, **kwargs
595
635
self . safe_load f , filename : filename , **kwargs
596
636
}
597
637
end
638
+ class << self ; alias load_file safe_load_file end
598
639
599
640
# :stopdoc:
600
641
def self . add_domain_type domain , type_tag , &block
0 commit comments