From ae9be137133530913d4ee13980eabc2577de317f Mon Sep 17 00:00:00 2001 From: Vishal Telangre Date: Wed, 15 May 2019 22:25:59 +0530 Subject: Fix: DummyCompiler embeds invalid YAML content Fixes https://github.com/rails/rails/issues/36285. Follow up of https://github.com/rails/rails/pull/36237. --- railties/lib/rails/application/dummy_erb_compiler.rb | 10 ++-------- railties/test/application/rake/dbs_test.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/railties/lib/rails/application/dummy_erb_compiler.rb b/railties/lib/rails/application/dummy_erb_compiler.rb index 086b9e76f4..028e790292 100644 --- a/railties/lib/rails/application/dummy_erb_compiler.rb +++ b/railties/lib/rails/application/dummy_erb_compiler.rb @@ -11,14 +11,8 @@ end class DummyCompiler < ERB::Compiler # :nodoc: def compile_content(stag, out) - case stag - when "<%=" - content = out.instance_variable_get(:@compiler).instance_variable_get(:@content) - if content.include?("?") && content.include?(":") - out.push "_erbout << 'dummy_key: dummy_value'" - else - out.push "_erbout << 'dummy_value'" - end + if stag == "<%=" + out.push "_erbout << ''" end end end diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index ca2d45b1c9..e08cd09abd 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -138,6 +138,23 @@ module ApplicationTests db_create_and_drop("db/development.sqlite3", environment_loaded: false) end + test "db:create and db:drop don't raise errors when loading YAML which contains a key's value as an ERB statement" do + app_file "config/database.yml", <<-YAML + development: + database: <%= Rails.application.config.database ? 'db/development.sqlite3' : 'db/development.sqlite3' %> + custom_option: <%= ENV['CUSTOM_OPTION'] %> + adapter: sqlite3 + YAML + + app_file "config/environments/development.rb", <<-RUBY + Rails.application.configure do + config.database = "db/development.sqlite3" + end + RUBY + + db_create_and_drop("db/development.sqlite3", environment_loaded: false) + end + def with_database_existing Dir.chdir(app_path) do set_database_url -- cgit v1.2.3