erb.rb: Allow trimming CR in all trim_modes

to unify a behavior with r58823 and r58825.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
k0kubun 2017-05-20 17:36:09 +00:00
Родитель b82ed2ce61
Коммит 64c914706e
3 изменённых файлов: 15 добавлений и 2 удалений

5
NEWS
Просмотреть файл

@ -88,6 +88,11 @@ with all sufficient information, see the ChangeLog file or Redmine
* New constants:
* RbConfig::LIMITS is added to provide the limits of C types.
* ERB
* Carriage returns are changed to be trimmed properly if trim_mode is specified
and used. Duplicated newlines will be removed on Windows.
[Bug #5339] [Bug #11464]
=== Compatibility issues (excluding feature bug fixes)
* Net::HTTP

Просмотреть файл

@ -389,7 +389,7 @@ class ERB
@trim_mode = trim_mode
@percent = percent
if @trim_mode == '>'
@scan_reg = /(.*?)(%>\n|#{(stags + etags).join('|')}|\n|\z)/m
@scan_reg = /(.*?)(%>\r?\n|#{(stags + etags).join('|')}|\n|\z)/m
@scan_line = self.method(:trim_line1)
elsif @trim_mode == '<>'
@scan_reg = /(.*?)(%>\r?\n|#{(stags + etags).join('|')}|\n|\z)/m
@ -441,7 +441,7 @@ class ERB
line.scan(@scan_reg) do |tokens|
tokens.each do |token|
next if token.empty?
if token == "%>\n"
if token == "%>\n" || token == "%>\r\n"
yield('%>')
yield(:cr)
else

Просмотреть файл

@ -197,6 +197,14 @@ EOS
assert_equal(ans, erb.result)
end
def test_trim_line1_with_carriage_return
erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", nil, '>')
assert_equal("line\r\n" * 3, erb.result)
erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", nil, '%>')
assert_equal("line\r\n" * 3, erb.result)
end
def test_trim_line2_with_carriage_return
erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", nil, '<>')
assert_equal("line\r\n" * 3, erb.result)