Skip to content

Commit 9e9c20e

Browse files
cboosgettalong
authored andcommitted
Fix loading of config file with recent Rubies (Psych 4.0)
Using Ruby 3.2, the following command would fail like this without the fix: > bin\kramdown --config-file .kramdown.yml -i GFM -o html README.md .../ruby-3.2-lean/lib/ruby/3.2.0/psych.rb:322:in `safe_load': wrong number of arguments (given 2, expected 1) (ArgumentError) from .../vendor/ruby/3.2.0/gems/kramdown-2.4.0/bin/kramdown:114:in `<top (required)>' from .../bin/kramdown.cmd:30:in `load' from .../bin/kramdown.cmd:30:in `<main>'
1 parent 98f8e61 commit 9e9c20e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

bin/kramdown

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ end.parse!
111111

112112
begin
113113
if config_file && File.exist?(config_file)
114-
config_file_options = YAML.safe_load(File.read(config_file), [Symbol])
114+
config_file_options =
115+
if YAML.method(:safe_load).parameters.include?(%i[key permitted_classes])
116+
YAML.safe_load(File.read(config_file), permitted_classes: [Symbol])
117+
else # compatibility with Psych < 3.1.0
118+
YAML.safe_load(File.read(config_file), [Symbol])
119+
end
115120
case config_file_options
116121
when nil # empty configuration file except perhaps YAML header and comments
117122
# Nothing to do

0 commit comments

Comments
 (0)