From a5824346d4ef14b05d0b699397cf2a6f8fe91617 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Wed, 16 Dec 2015 15:44:22 -0700 Subject: [PATCH] fix merge constructs with safe_yaml see https://github.com/dtao/safe_yaml/issues/81 and https://github.com/dtao/safe_yaml/issues/82 test plan: * have a merge construct in your database.yml * canvas should boot Change-Id: Ie5ca4dfac5d9fe4e62ad89474a2eb7d84feae02c Reviewed-on: https://gerrit.instructure.com/69083 Tested-by: Jenkins Reviewed-by: Simon Williams Product-Review: August Thornton QA-Review: August Thornton --- config/application.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index ad2828d1e389..9011b79a16e2 100644 --- a/config/application.rb +++ b/config/application.rb @@ -189,6 +189,18 @@ def postgresql_connection(config) # :nodoc: val.constantize end + trusted_tags = SafeYAML::TRUSTED_TAGS.dup + trusted_tags << 'tag:yaml.org,2002:merge' + SafeYAML.send(:remove_const, :TRUSTED_TAGS) + SafeYAML.const_set(:TRUSTED_TAGS, trusted_tags.freeze) + module FixSafeYAMLNullMerge + def merge_into_hash(hash, array) + return unless array + super + end + end + SafeYAML::Resolver.prepend(FixSafeYAMLNullMerge) + SafeYAML::OPTIONS.merge!( default_mode: :safe, deserialize_symbols: true, @@ -198,7 +210,6 @@ def postgresql_connection(config) # :nodoc: whitelisted_tags: %w[ tag:ruby.yaml.org,2002:symbol tag:yaml.org,2002:float - tag:yaml.org,2002:merge tag:yaml.org,2002:str tag:yaml.org,2002:timestamp tag:yaml.org,2002:timestamp#iso8601