mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c02f036090
commit
1ae3e6f3ce
2 changed files with 10 additions and 2 deletions
|
@ -814,7 +814,7 @@ 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
|
||||
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
|
|||
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
|
||||
|
|
|
@ -663,12 +663,18 @@ EOS
|
|||
|
||||
# [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
|
||||
ERB.new('', nil, trim)
|
||||
|
|
Loading…
Reference in a new issue