ruby-changes:46710
From: k0kubun <ko1@a...>
Date: Sun, 21 May 2017 02:17:29 +0900 (JST)
Subject: [ruby-changes:46710] k0kubun:r58825 (trunk): erb.rb: Allow explicit trimming carriage return
k0kubun 2017-05-21 02:17:22 +0900 (Sun, 21 May 2017) New Revision: 58825 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58825 Log: erb.rb: Allow explicit trimming carriage return when trim_mode is "-", for Windows environments. [ruby-core:39625] [Bug #5339] Modified files: trunk/lib/erb.rb trunk/test/erb/test_erb.rb Index: test/erb/test_erb.rb =================================================================== --- test/erb/test_erb.rb (revision 58824) +++ test/erb/test_erb.rb (revision 58825) @@ -200,6 +200,17 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L200 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) + + 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_explicit_trim_line_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 class Foo; end Index: lib/erb.rb =================================================================== --- lib/erb.rb (revision 58824) +++ lib/erb.rb (revision 58825) @@ -395,7 +395,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L395 @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 + @scan_reg = /(.*?)(^[ \t]*<%\-|<%\-|-%>\r?\n|-%>|#{(stags + etags).join('|')}|\z)/m @scan_line = self.method(:explicit_trim_line) else @scan_reg = /(.*?)(#{(stags + etags).join('|')}|\n|\z)/m @@ -479,7 +479,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L479 next if token.empty? if @stag.nil? && /[ \t]*<%-/ =~ token yield('<%') - elsif @stag && token == "-%>\n" + elsif @stag && (token == "-%>\n" || token == "-%>\r\n") yield('%>') yield(:cr) elsif @stag && token == '-%>' @@ -534,7 +534,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L534 yield('<%') elsif elem == '-%>' yield('%>') - yield(:cr) if scanner.scan(/(\n|\z)/) + yield(:cr) if scanner.scan(/(\r?\n|\z)/) else yield(elem) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/