diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index c2e74eb2..e01f798c 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -110,7 +110,7 @@ module Jekyll Jekyll::External.require_with_graceful_fail('toml') unless defined?(TOML) TOML.load_file(filename) when /\.ya?ml/i - SafeYAML.load_file(filename) + SafeYAML.load_file(filename) || {} else raise ArgumentError, "No parser for '#{filename}' is available. Use a .toml or .y(a)ml file instead." end @@ -145,7 +145,7 @@ module Jekyll # Returns this configuration, overridden by the values in the file def read_config_file(file) next_config = safe_load_file(file) - raise ArgumentError.new("Configuration file: (INVALID) #{file}".yellow) unless next_config.is_a?(Hash) + check_config_is_hash!(next_config, file) Jekyll.logger.info "Configuration file:", file next_config rescue SystemCallError @@ -228,7 +228,8 @@ module Jekyll end %w[include exclude].each do |option| - if config.fetch(option, []).is_a?(String) + config[option] ||= [] + if config[option].is_a?(String) Jekyll::Deprecator.deprecation_message "The '#{option}' configuration option" + " must now be specified as an array, but you specified" + " a string. For now, we've treated the string you provided" + @@ -292,6 +293,7 @@ module Jekyll end private + def style_to_permalink(permalink_style) case permalink_style.to_sym when :pretty @@ -306,5 +308,17 @@ module Jekyll permalink_style.to_s end end + + # Private: Checks if a given config is a hash + # + # extracted_config - the value to check + # file - the file from which the config was extracted + # + # Raises an ArgumentError if given config is not a hash + def check_config_is_hash!(extracted_config, file) + unless extracted_config.is_a?(Hash) + raise ArgumentError.new("Configuration file: (INVALID) #{file}".yellow) + end + end end end diff --git a/test/test_configuration.rb b/test/test_configuration.rb index 553dfda3..608dfef0 100644 --- a/test/test_configuration.rb +++ b/test/test_configuration.rb @@ -59,6 +59,34 @@ class TestConfiguration < JekyllUnitTest assert_equal %w[config/site.yml config/deploy.toml configuration.yml], @config.config_files(@multiple_files) end end + + context "#read_config_file" do + setup do + @config = Configuration[{"source" => source_dir('empty.yml')}] + end + + should "not raise an error on empty files" do + allow(SafeYAML).to receive(:load_file).with('empty.yml').and_return(false) + Jekyll.logger.log_level = :warn + @config.read_config_file('empty.yml') + Jekyll.logger.log_level = :info + end + end + + context "#read_config_files" do + setup do + @config = Configuration[{"source" => source_dir}] + end + + should "continue to read config files if one is empty" do + allow(SafeYAML).to receive(:load_file).with('empty.yml').and_return(false) + allow(SafeYAML).to receive(:load_file).with('not_empty.yml').and_return({'foo' => 'bar', 'include' => '', 'exclude' => ''}) + Jekyll.logger.log_level = :warn + read_config = @config.read_config_files(['empty.yml', 'not_empty.yml']) + Jekyll.logger.log_level = :info + assert_equal 'bar', read_config['foo'] + end + end context "#backwards_compatibilize" do setup do @config = Configuration[{