aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishal Telangre <the@vishaltelangre.com>2019-05-15 22:25:59 +0530
committerVishal Telangre <the@vishaltelangre.com>2019-05-15 22:26:07 +0530
commitae9be137133530913d4ee13980eabc2577de317f (patch)
treecec3393d7e90ccfc7b20b6d5e0b211f3d4475ee5
parent13d6aa3a7b70bca66c4abda7721329ad1863c24c (diff)
downloadrails-ae9be137133530913d4ee13980eabc2577de317f.tar.gz
rails-ae9be137133530913d4ee13980eabc2577de317f.tar.bz2
rails-ae9be137133530913d4ee13980eabc2577de317f.zip
Fix: DummyCompiler embeds invalid YAML content
Fixes https://github.com/rails/rails/issues/36285. Follow up of https://github.com/rails/rails/pull/36237.
-rw-r--r--railties/lib/rails/application/dummy_erb_compiler.rb10
-rw-r--r--railties/test/application/rake/dbs_test.rb17
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