ruby-changes:54417
From: k0kubun <ko1@a...>
Date: Sat, 29 Dec 2018 16:26:27 +0900 (JST)
Subject: [ruby-changes:54417] k0kubun:r66632 (trunk): erb.rb: increase warn level only when non-zero safe_level
k0kubun 2018-12-29 16:26:22 +0900 (Sat, 29 Dec 2018) New Revision: 66632 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66632 Log: erb.rb: increase warn level only when non-zero safe_level is given. This is merging Eric's patch in [Bug #15479] to Ruby 2.6's behavior in r66631. Modified files: trunk/lib/erb.rb trunk/test/erb/test_erb.rb Index: test/erb/test_erb.rb =================================================================== --- test/erb/test_erb.rb (revision 66631) +++ test/erb/test_erb.rb (revision 66632) @@ -663,11 +663,17 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L663 # [deprecated] These interfaces will be removed later def test_deprecated_interface_warnings - [nil, 0, 1, 2].each do |safe| + [nil, 0].each do |safe| assert_warning(/2nd argument of ERB.new is deprecated/) do ERB.new('', safe) end end + + [1, 2].each do |safe| + assert_warn(/2nd argument of ERB.new is deprecated/) do + ERB.new('', safe) + end + end [nil, '', '%', '%<>'].each do |trim| assert_warning(/3rd argument of ERB.new is deprecated/) do Index: lib/erb.rb =================================================================== --- lib/erb.rb (revision 66631) +++ lib/erb.rb (revision 66632) @@ -814,7 +814,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L814 def initialize(str, safe_level=NOT_GIVEN, legacy_trim_mode=NOT_GIVEN, legacy_eoutvar=NOT_GIVEN, trim_mode: nil, eoutvar: '_erbout') # Complex initializer for $SAFE deprecation at [Feature #14256]. Use keyword arguments to pass trim_mode or eoutvar. if safe_level != NOT_GIVEN - warn 'Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments.', uplevel: 1 if $VERBOSE + warn 'Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments.', uplevel: 1 if $VERBOSE || !ZERO_SAFE_LEVELS.include?(safe_level) else safe_level = nil end @@ -836,6 +836,8 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L836 end NOT_GIVEN = Object.new private_constant :NOT_GIVEN + ZERO_SAFE_LEVELS = [0, nil] + private_constant :ZERO_SAFE_LEVELS ## # Creates a new compiler for ERB. See ERB::Compiler.new for details -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/