Defect #44722 ยป 0001-Process-database.yml-with-ERB-in-a-separate-process-.patch
| Gemfile | ||
|---|---|---|
| 59 | 59 |
if File.exist?(database_file) |
| 60 | 60 |
database_config = File.read(database_file) |
| 61 | 61 | |
| 62 |
# Requiring libraries in a Gemfile may cause Bundler warnings or |
|
| 63 |
# unexpected behavior, especially if multiple gem versions are available. |
|
| 64 |
# So, process database.yml through ERB only if it contains ERB syntax |
|
| 65 |
# in the adapter setting. See https://www.redmine.org/issues/41749. |
|
| 62 |
# Process database.yml with ERB in a separate Ruby process, because |
|
| 63 |
# requiring erb here may activate a version that conflicts with |
|
| 64 |
# Gemfile.lock (#41749). |
|
| 66 | 65 |
if database_config.match?(/^ *adapter: *<%=/) |
| 67 |
require 'erb' |
|
| 68 |
database_config = ERB.new(database_config).result |
|
| 66 |
# Send output from the ERB code to stderr to keep it out of the result |
|
| 67 |
erb_script = <<~RUBY |
|
| 68 |
$stdout = STDERR |
|
| 69 |
STDOUT.write(ERB.new(File.read(ARGV.fetch(0))).result) |
|
| 70 |
RUBY |
|
| 71 |
# Without the unbundled env, the child process would load this Gemfile |
|
| 72 |
# again through RUBYOPT=-rbundler/setup |
|
| 73 |
database_config = Bundler.with_unbundled_env do |
|
| 74 |
IO.popen([RbConfig.ruby, '-rerb', '-e', erb_script, database_file], &:read) |
|
| 75 |
end |
|
| 76 |
raise "Could not evaluate ERB in #{database_file}" unless $?.success?
|
|
| 69 | 77 |
end |
| 70 | 78 | |
| 71 | 79 |
adapters = database_config.scan(/^ *adapter: *(.*)/).flatten.uniq |