ruby-changes:64974
From: Takashi <ko1@a...>
Date: Thu, 21 Jan 2021 13:52:22 +0900 (JST)
Subject: [ruby-changes:64974] 922989fa0f (master): [ruby/erb] Warn safe_level and later args even without -w
https://git.ruby-lang.org/ruby.git/commit/?id=922989fa0f From 922989fa0f1bf1e13b2c9bf1c8d6ad9459c798f6 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Wed, 20 Jan 2021 20:45:55 -0800 Subject: [ruby/erb] Warn safe_level and later args even without -w because, when Ruby 3.1 is released, Ruby 2.5, the last version with the old method signature, will have been EOL. Therefore we can safely warn the old interface from Ruby 3.1. https://github.com/ruby/erb/commit/c3a753f49f diff --git a/lib/erb.rb b/lib/erb.rb index d2ea64a..f8533ef 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -809,14 +809,14 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L809 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 || !ZERO_SAFE_LEVELS.include?(safe_level) + 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 end if legacy_trim_mode != NOT_GIVEN - warn 'Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead.', uplevel: 1 if $VERBOSE + warn 'Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead.', uplevel: 1 trim_mode = legacy_trim_mode end if legacy_eoutvar != NOT_GIVEN - warn 'Passing eoutvar with the 4th argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, eoutvar: ...) instead.', uplevel: 1 if $VERBOSE + warn 'Passing eoutvar with the 4th argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, eoutvar: ...) instead.', uplevel: 1 eoutvar = legacy_eoutvar end @@ -829,8 +829,6 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L829 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 diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb index d3e9b6c..fb5e9b6 100644 --- a/test/erb/test_erb.rb +++ b/test/erb/test_erb.rb @@ -663,26 +663,20 @@ 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].each do |safe| - assert_warning(/2nd argument of ERB.new is deprecated/) do - ERB.new('', safe) - end - end - - [1, 2].each do |safe| + [nil, 0, 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 + assert_warn(/3rd argument of ERB.new is deprecated/) do ERB.new('', nil, trim) end end [nil, '_erbout', '_hamlout'].each do |eoutvar| - assert_warning(/4th argument of ERB.new is deprecated/) do + assert_warn(/4th argument of ERB.new is deprecated/) do ERB.new('', nil, nil, eoutvar) end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/