From 9e9c20e06e4493832efed564e03cecaeb83cf2cd Mon Sep 17 00:00:00 2001 From: Christian Boos Date: Fri, 17 Feb 2023 19:15:08 +0100 Subject: [PATCH] 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 `' from .../bin/kramdown.cmd:30:in `load' from .../bin/kramdown.cmd:30:in `
' --- bin/kramdown | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/kramdown b/bin/kramdown index e1128abe..3b7f3469 100755 --- a/bin/kramdown +++ b/bin/kramdown @@ -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