Skip to content

Commit

Permalink
Merge pull request #32170 from koic/deprecate_safe_level_of_erb_new_i…
Browse files Browse the repository at this point in the history
…n_ruby_2_6

Deprecate safe_level of `ERB.new` in Ruby 2.6
  • Loading branch information
kamipo committed Mar 5, 2018
2 parents ae2d36c + e8be4f0 commit d13ce1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion railties/lib/rails/generators/migration.rb
Expand Up @@ -63,7 +63,12 @@ def migration_template(source, destination, config = {})
numbered_destination = File.join(dir, ["%migration_number%", base].join("_"))

create_migration numbered_destination, nil, config do
ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /)
if match && match[:version] >= "2.2.0" # Ruby 2.6+
ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(context)
else
ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
end
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion tasks/release.rb
Expand Up @@ -247,6 +247,12 @@ def rc?

require "erb"
template = File.read("../tasks/release_announcement_draft.erb")
puts ERB.new(template, nil, "<>").result(binding)

match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /)
if match && match[:version] >= "2.2.0" # Ruby 2.6+
puts ERB.new(template, trim_mode: "<>").result(binding)
else
puts ERB.new(template, nil, "<>").result(binding)
end
end
end

0 comments on commit d13ce1f

Please sign in to comment.