summaryrefslogtreecommitdiff
path: root/ext/psych
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2021-05-17 23:09:37 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-06-07 19:15:14 +0900
commit430883158f3d01f80917d6eefbaa82521c95c05a (patch)
tree3046a244aa2333460759859d4bc0a22dd1f6173e /ext/psych
parentdd765f9e605eb1a6426a0e3165e2db71b2081d03 (diff)
[ruby/psych] Make YAML.load_file use YAML.load instead of safe_load
YAML.load and YAML.safe_load are different a little; the former allows Symbol by default but the latter doesn't. So YAML.load_file and YAML.safe_load_file should reflect the difference. Fixes #490 https://github.com/ruby/psych/commit/f8a5e512a1
Diffstat (limited to 'ext/psych')
-rw-r--r--ext/psych/lib/psych.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb
index 7c6b8d0..6205061 100644
--- a/ext/psych/lib/psych.rb
+++ b/ext/psych/lib/psych.rb
@@ -575,7 +575,6 @@ module Psych
self.unsafe_load f, filename: filename, **kwargs
}
end
- class << self; alias :load_file :unsafe_load_file; end
###
# Safely loads the document contained in +filename+. Returns the yaml contained in
@@ -587,7 +586,17 @@ module Psych
self.safe_load f, filename: filename, **kwargs
}
end
- class << self; alias load_file safe_load_file end
+
+ ###
+ # Loads 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+.
+ # See load for options.
+ def self.load_file filename, **kwargs
+ File.open(filename, 'r:bom|utf-8') { |f|
+ self.load f, filename: filename, **kwargs
+ }
+ end
# :stopdoc:
def self.add_domain_type domain, type_tag, &block