reset default hash value in sets after yaml deserialization

Change-Id: Iea5625cd6a98082af65a045b63045c36af874c15
Reviewed-on: https://gerrit.instructure.com/201413
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins
This commit is contained in:
James Williams 2019-07-16 13:21:38 -06:00
parent 503983e64b
commit f0ce4f9996
2 changed files with 11 additions and 2 deletions

View File

@ -242,8 +242,13 @@ SafeYAML::Transform.singleton_class.prepend(ScalarTransformFix)
module YAMLSingletonFix
def revive(klass, node)
return klass.instance if klass < Singleton
super
if klass < Singleton
klass.instance
elsif klass == Set
super.tap{|s| s.instance_variable_get(:@hash).default = false}
else
super
end
end
end
Psych::Visitors::ToRuby.prepend(YAMLSingletonFix)

View File

@ -205,4 +205,8 @@ YAML
it "dumps and loads singletons" do
expect(YAML.load(YAML.dump(Mime::NullType.instance))).to eq Mime::NullType.instance
end
it "restores default value on sets on load" do
expect(YAML.unsafe_load(YAML.dump(Set.new)).include?("test")).to eq false
end
end