Skip to content

Commit

Permalink
Fix loading of config file with recent Rubies (Psych 4.0)
Browse files Browse the repository at this point in the history
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>'
  • Loading branch information
Christian Boos authored and gettalong committed Mar 15, 2023
1 parent 98f8e61 commit 9e9c20e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bin/kramdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ end.parse!

begin
if config_file && File.exist?(config_file)
config_file_options = YAML.safe_load(File.read(config_file), [Symbol])
config_file_options =
if YAML.method(:safe_load).parameters.include?(%i[key permitted_classes])
YAML.safe_load(File.read(config_file), permitted_classes: [Symbol])
else # compatibility with Psych < 3.1.0
YAML.safe_load(File.read(config_file), [Symbol])
end
case config_file_options
when nil # empty configuration file except perhaps YAML header and comments
# Nothing to do
Expand Down

0 comments on commit 9e9c20e

Please sign in to comment.