Bug #15478 » 0001-erb-remove-deprecation-warnings-from-ERB.new.patch
lib/erb.rb | ||
---|---|---|
#
|
||
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], which should be removed at a version later than 2.7.
|
||
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
|
||
else
|
||
case safe_level
|
||
when NOT_GIVEN, nil, 0
|
||
safe_level = nil
|
||
else
|
||
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
|
||
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
|
||
eoutvar = legacy_eoutvar
|
||
end
|
||
test/erb/test_erb.rb | ||
---|---|---|
# These interfaces will be removed later than Ruby 2.7.
|
||
def test_deprecated_interface_warnings
|
||
[nil, 0, 1, 2].each do |safe|
|
||
[nil, 0].each do |safe|
|
||
assert_no_warning(/2nd argument of ERB.new is deprecated/) do
|
||
ERB.new('', safe)
|
||
end
|
||
end
|
||
[1, 2].each do |safe|
|
||
assert_warning(/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_no_warning(/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_no_warning(/4th argument of ERB.new is deprecated/) do
|
||
ERB.new('', nil, nil, eoutvar)
|
||
end
|
||
end
|
||
-
|