ruby-changes:46708
From: k0kubun <ko1@a...>
Date: Sun, 21 May 2017 01:50:38 +0900 (JST)
Subject: [ruby-changes:46708] k0kubun:r58823 (trunk): erb.rb: Allow trimming carriage return
k0kubun 2017-05-21 01:50:33 +0900 (Sun, 21 May 2017) New Revision: 58823 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58823 Log: erb.rb: Allow trimming carriage return when trim_mode is "<>", for Windows environments. [Bug #11464] Modified files: trunk/lib/erb.rb trunk/test/erb/test_erb.rb Index: lib/erb.rb =================================================================== --- lib/erb.rb (revision 58822) +++ lib/erb.rb (revision 58823) @@ -392,7 +392,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L392 @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 https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L457 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) Index: test/erb/test_erb.rb =================================================================== --- test/erb/test_erb.rb (revision 58822) +++ test/erb/test_erb.rb (revision 58823) @@ -197,6 +197,11 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L197 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/