]> source.dussan.org Git - redmine.git/commitdiff
Merged r23269 from trunk to 5.1-stable (#41749).
authorGo MAEDA <maeda@farend.jp>
Sun, 17 Nov 2024 04:56:19 +0000 (04:56 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 17 Nov 2024 04:56:19 +0000 (04:56 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@23286 e93f8b46-1217-0410-a6f0-8f06a7374b81

Gemfile

diff --git a/Gemfile b/Gemfile
index 8e79c405936253216a79b7d8b0345e5adbd2da32..290011946b8fe79c1fb2fee4ce53a7f0f5add08a 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -57,16 +57,23 @@ end
 
 # Include database gems for the adapters found in the database
 # configuration file
-require 'erb'
-require 'yaml'
 database_file = File.join(File.dirname(__FILE__), "config/database.yml")
 if File.exist?(database_file)
-  yaml_config = ERB.new(IO.read(database_file)).result
-  database_config = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(yaml_config) : YAML.load(yaml_config)
-  adapters = database_config.values.filter_map {|c| c['adapter']}.uniq
+  database_config = File.read(database_file)
+
+  # Requiring libraries in a Gemfile may cause Bundler warnings or
+  # unexpected behavior, especially if multiple gem versions are available.
+  # So, process database.yml through ERB only if it contains ERB syntax
+  # in the adapter setting. See https://www.redmine.org/issues/41749.
+  if database_config.match?(/^ *adapter: *<%=/)
+    require 'erb'
+    database_config = ERB.new(database_config).result
+  end
+
+  adapters = database_config.scan(/^ *adapter: *(.*)/).flatten.uniq
   if adapters.any?
     adapters.each do |adapter|
-      case adapter
+      case adapter.strip
       when 'mysql2'
         gem "mysql2", "~> 0.5.0", :platforms => [:mri, :mingw, :x64_mingw]
         gem "with_advisory_lock"