Defect #44722 ยป 0001-Process-database.yml-with-ERB-in-a-separate-process-.patch
| Gemfile | ||
|---|---|---|
|
if File.exist?(database_file)
|
||
|
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.
|
||
|
# Process database.yml with ERB in a separate Ruby process, because
|
||
|
# requiring erb here may activate a version that conflicts with
|
||
|
# Gemfile.lock (#41749).
|
||
|
if database_config.match?(/^ *adapter: *<%=/)
|
||
|
require 'erb'
|
||
|
database_config = ERB.new(database_config).result
|
||
|
# Send output from the ERB code to stderr to keep it out of the result
|
||
|
erb_script = <<~RUBY
|
||
|
$stdout = STDERR
|
||
|
STDOUT.write(ERB.new(File.read(ARGV.fetch(0))).result)
|
||
|
RUBY
|
||
|
# Without the unbundled env, the child process would load this Gemfile
|
||
|
# again through RUBYOPT=-rbundler/setup
|
||
|
database_config = Bundler.with_unbundled_env do
|
||
|
IO.popen([RbConfig.ruby, '-rerb', '-e', erb_script, database_file], &:read)
|
||
|
end
|
||
|
raise "Could not evaluate ERB in #{database_file}" unless $?.success?
|
||
|
end
|
||
|
adapters = database_config.scan(/^ *adapter: *(.*)/).flatten.uniq
|
||