Skip to content

Commit

Permalink
Merge pull request #1385 from MSP-Greg/psych-4
Browse files Browse the repository at this point in the history
Config.read_config_file - use safe_load_file if available
  • Loading branch information
lsegal authored Jun 1, 2022
2 parents a80a728 + 285278b commit 4c0c9c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/yard/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ def self.translate_plugin_names
def self.read_config_file
if File.file?(CONFIG_FILE)
require 'yaml'
YAML.load_file(CONFIG_FILE)
if YAML.respond_to?(:safe_load_file)
YAML.safe_load_file(CONFIG_FILE, permitted_classes: [SymbolHash, Symbol])
else
YAML.load_file(CONFIG_FILE)
end
else
{}
end
Expand Down
8 changes: 7 additions & 1 deletion spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
it "overwrites options with data in ~/.yard/config" do
expect(File).to receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(true)
expect(File).to receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(false)
expect(YAML).to receive(:load_file).with(YARD::Config::CONFIG_FILE).and_return('test' => true)
if YAML.respond_to?(:safe_load_file)
expect(YAML).to receive(:safe_load_file)
.with(YARD::Config::CONFIG_FILE, permitted_classes: [SymbolHash, Symbol])
.and_return('test' => true)
else
expect(YAML).to receive(:load_file).with(YARD::Config::CONFIG_FILE).and_return('test' => true)
end
YARD::Config.load
expect(YARD::Config.options[:test]).to be true
end
Expand Down

0 comments on commit 4c0c9c8

Please sign in to comment.