Project

General

Profile

Misc #15294 ยป erb_trim_mode_warning.patch

Add warnings for invalid ERB trim modes - jsc (Justin Collins), 11/09/2018 09:02 PM

View differences:

lib/erb.rb
when 0
return [false, nil]
when String
warn "Invalid ERB trim mode: #{mode.inspect}", uplevel: 5 unless mode.match?(/\A(%|-|>|<>){1,2}\z/)
perc = mode.include?('%')
if mode.include?('-')
return [perc, '-']
......
[perc, nil]
end
else
warn "Invalid ERB trim mode: #{mode.inspect}", uplevel: 5 unless mode.nil?
return [false, nil]
end
end
test/erb/test_erb.rb
assert_equal("line\r\n" * 3, erb.result)
end
def test_invalid_trim_mode
assert_warning(/Invalid ERB trim mode/) do
@erb.new("", trim_mode: 'abc-def')
end
assert_warning(/Invalid ERB trim mode/) do
@erb.new("", trim_mode: '%<')
end
assert_warning(/Invalid ERB trim mode/) do
@erb.new("", trim_mode: '%<>-')
end
assert_warning(/Invalid ERB trim mode/) do
@erb.new("", trim_mode: 3)
end
end
def test_run
out = StringIO.new
orig, $stdout = $stdout, out
    (1-1/1)