diff --git a/lib/serverspec/type/file.rb b/lib/serverspec/type/file.rb index 0a20b761..340bde8a 100644 --- a/lib/serverspec/type/file.rb +++ b/lib/serverspec/type/file.rb @@ -121,7 +121,13 @@ def content_as_json end def content_as_yaml - @content_as_yaml = YAML.load(content) if @content_as_yaml.nil? + if @content_as_yaml.nil? + @content_as_yaml = if YAML.respond_to?(:unsafe_load) + YAML.unsafe_load(content) + else + YAML.load(content) + end + end @content_as_yaml end diff --git a/spec/type/base/file_spec.rb b/spec/type/base/file_spec.rb index 0b80f8ac..7974f20e 100644 --- a/spec/type/base/file_spec.rb +++ b/spec/type/base/file_spec.rb @@ -369,18 +369,22 @@ let(:stdout) {< include('title' => 'this is a yaml')) } its(:content_as_yaml) { should include('yaml' => include('array' => include('title' => 'array 2'))) } + its(:content_as_yaml) { should include('yaml' => include('date' => Date.new(2023, 2, 3))) } + its(:content_as_yaml) { should include('yaml' => include('Reuse anchor' => 'this is a yaml')) } end