Skip to content

Commit 285278b

Browse files
committed
Config.read_config_file - use safe_load_file if available
Psych 4+ may change load_file behavior
1 parent b589fa0 commit 285278b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/yard/config.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ def self.translate_plugin_names
236236
def self.read_config_file
237237
if File.file?(CONFIG_FILE)
238238
require 'yaml'
239-
YAML.load_file(CONFIG_FILE)
239+
if YAML.respond_to?(:safe_load_file)
240+
YAML.safe_load_file(CONFIG_FILE, permitted_classes: [SymbolHash, Symbol])
241+
else
242+
YAML.load_file(CONFIG_FILE)
243+
end
240244
else
241245
{}
242246
end

spec/config_spec.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
it "overwrites options with data in ~/.yard/config" do
1818
expect(File).to receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(true)
1919
expect(File).to receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(false)
20-
expect(YAML).to receive(:load_file).with(YARD::Config::CONFIG_FILE).and_return('test' => true)
20+
if YAML.respond_to?(:safe_load_file)
21+
expect(YAML).to receive(:safe_load_file)
22+
.with(YARD::Config::CONFIG_FILE, permitted_classes: [SymbolHash, Symbol])
23+
.and_return('test' => true)
24+
else
25+
expect(YAML).to receive(:load_file).with(YARD::Config::CONFIG_FILE).and_return('test' => true)
26+
end
2127
YARD::Config.load
2228
expect(YARD::Config.options[:test]).to be true
2329
end

0 commit comments

Comments
 (0)