From 948394f87bc501095ca05bfa46d3f4f8d1badfdd Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 5 Nov 2024 12:42:52 +0100 Subject: [PATCH] Fix puppet classes import filter when using Ruby >=3.1 and Regexp/Symbol in YAML file Co-authored-by: Ewoud Kohl van Wijngaarden --- app/services/foreman_puppet/puppet_class_importer.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/services/foreman_puppet/puppet_class_importer.rb b/app/services/foreman_puppet/puppet_class_importer.rb index 94eeeadb..f8051cc3 100644 --- a/app/services/foreman_puppet/puppet_class_importer.rb +++ b/app/services/foreman_puppet/puppet_class_importer.rb @@ -229,7 +229,17 @@ def ignored_file_path end def load_ignored_file - File.exist?(ignored_file_path) ? YAML.load_file(ignored_file_path) : {} + if File.exist?(ignored_file_path) + # Ruby 3+ + if YAML.respond_to(:safe_load_file) + YAML.safe_load_file(ignored_file_path, permitted_classes: [Symbol, Regexp]) + else + # NOTE: Once we drop Ruby 2.7 support, you can drop the load_file call. + YAML.load_file(ignored_file_path) + end + else + {} + end end def ignored_file