From b61531a32688ef5e006a03be2ebef0919515bf81 Mon Sep 17 00:00:00 2001
From: Ryan Davis <ryand-ruby@zenspider.com>
Date: Tue, 28 Dec 2021 15:20:23 -0800
Subject: [PATCH] - Fixed loading config files for ruby 3.1's now default
 YAML.safe_load_file. [git-p4: depot-paths = "//src/hoe/dev/": change = 13295]

---
 lib/hoe.rb | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

--- a/lib/hoe.rb
+++ b/lib/hoe.rb
@@ -915,19 +915,29 @@
     config = Hoe::DEFAULT_CONFIG
 
     rc = File.expand_path("~/.hoerc")
-    exists = File.exist? rc
-    homeconfig = exists ? YAML.load_file(rc) : {}
+    homeconfig = maybe_load_yaml rc
 
     config = config.merge homeconfig
 
     localrc = File.join Dir.pwd, ".hoerc"
-    exists = File.exist? localrc
-    localconfig = exists ? YAML.load_file(localrc) : {}
+    localconfig = maybe_load_yaml(localrc)
 
     config = config.merge localconfig
 
     yield config, rc
   end
+
+  def maybe_load_yaml path
+    if File.exist? path then
+      if YAML.respond_to? :safe_load_file then
+        YAML.safe_load_file path, permitted_classes: [Regexp, Symbol]
+      else
+        YAML.load_file path
+      end
+    else
+      {}
+    end
+  end
 end
 
 class File
