1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
parent b82ed2ce61
commit 64c914706e
3 changed files with 15 additions and 2 deletions

5
NEWS
View file

@ -88,6 +88,11 @@ with all sufficient information, see the ChangeLog file or Redmine
* New constants: * New constants:
* RbConfig::LIMITS is added to provide the limits of C types. * 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) === Compatibility issues (excluding feature bug fixes)
* Net::HTTP * Net::HTTP

View file

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

View file

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