Skip to content

Commit

Permalink
Warn safe_level and later args even without -w
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
k0kubun committed Jan 21, 2021
1 parent 6f86e3b commit c3a753f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
8 changes: 3 additions & 5 deletions lib/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -809,14 +809,14 @@ class ERB
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

Expand All @@ -829,8 +829,6 @@ def initialize(str, safe_level=NOT_GIVEN, legacy_trim_mode=NOT_GIVEN, legacy_eou
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
Expand Down
12 changes: 3 additions & 9 deletions test/erb/test_erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,26 +663,20 @@ def test_half_working_comment_backward_compatibility

# [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
Expand Down

0 comments on commit c3a753f

Please sign in to comment.