From 040f27569069926ca57e4d05e77b8a7bded6a7af Mon Sep 17 00:00:00 2001 From: k0kubun Date: Sat, 20 May 2017 16:50:33 +0000 Subject: [PATCH] erb.rb: Allow trimming carriage return when trim_mode is "<>", for Windows environments. [Bug #11464] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/erb.rb | 4 ++-- test/erb/test_erb.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/erb.rb b/lib/erb.rb index b1c993c001..57d068a331 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -392,7 +392,7 @@ class ERB @scan_reg = /(.*?)(%>\n|#{(stags + etags).join('|')}|\n|\z)/m @scan_line = self.method(:trim_line1) elsif @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_line2) elsif @trim_mode == '-' @scan_reg = /(.*?)(^[ \t]*<%\-|<%\-|-%>\n|-%>|#{(stags + etags).join('|')}|\z)/m @@ -457,7 +457,7 @@ class ERB tokens.each do |token| next if token.empty? head = token unless head - if token == "%>\n" + if token == "%>\n" || token == "%>\r\n" yield('%>') if is_erb_stag?(head) yield(:cr) diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb index 7a92de3630..f3f3c02820 100644 --- a/test/erb/test_erb.rb +++ b/test/erb/test_erb.rb @@ -197,6 +197,11 @@ EOS assert_equal(ans, 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) + end + class Foo; end def test_def_class