From d84844c2230948082de7a9270023f732a4542bb0 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 18 May 2016 12:48:42 -0700 Subject: [PATCH] Freeze configuration defaults & duplicate in deep_merge_hashes if need be. --- lib/jekyll/configuration.rb | 2 +- lib/jekyll/utils.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index a08c284c..475aa4e6 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -72,7 +72,7 @@ module Jekyll 'hard_wrap' => false, 'footnote_nr' => 1 } - }].freeze + }.map { |k, v| [k, v.freeze] }].freeze class << self # Static: Produce a Configuration ready for use in a Site. diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb index 179981ec..a70a7916 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -54,6 +54,10 @@ module Jekyll target.default_proc = overwrite.default_proc end + target.each do |key, val| + target[key] = val.dup if val.frozen? && duplicable?(val) + end + target end @@ -61,6 +65,15 @@ module Jekyll value.is_a?(Hash) || value.is_a?(Drops::Drop) end + def duplicable?(obj) + case obj + when nil, false, true, Symbol, Numeric + false + else + true + end + end + # Read array from the supplied hash favouring the singular key # and then the plural key, and handling any nil entries. #