Skip to content

Commit 0c4fa8e

Browse files
committed
(maint) Revise check for unsafe_load_file
It's possible to install Psych 5 with Ruby 2.7 causing YAML.load_file to call the safe version. So revise the check based on whether the unsafe_load_file method exists, and remove it when Ruby < 3.1 is dropped.
1 parent 45dffbe commit 0c4fa8e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

spec/unit/reports/store_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
end
1616

1717
let(:report) do
18-
if RUBY_VERSION < "3.0"
19-
report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml'))
20-
else
18+
# It's possible to install Psych 5 with Ruby 2.7, so check whether underlying YAML supports
19+
# unsafe_load_file. This check can be removed in PUP-11718
20+
if YAML.respond_to?(:unsafe_load_file)
2121
report = YAML.unsafe_load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml'))
22+
else
23+
report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml'))
2224
end
2325
report.extend(described_class)
2426
report

0 commit comments

Comments
 (0)