ruby-changes:47186
From: nagachika <ko1@a...>
Date: Mon, 10 Jul 2017 05:06:35 +0900 (JST)
Subject: [ruby-changes:47186] nagachika:r59301 (ruby_2_4): merge revision(s) 58825, 58826: [Backport #5339]
nagachika 2017-07-10 05:06:31 +0900 (Mon, 10 Jul 2017) New Revision: 59301 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59301 Log: merge revision(s) 58825,58826: [Backport #5339] erb.rb: Allow explicit trimming carriage return when trim_mode is "-", for Windows environments. [ruby-core:39625] [Bug #5339] erb.rb: Allow trimming CR in all trim_modes to unify a behavior with r58823 and r58825. Modified directories: branches/ruby_2_4/ Modified files: branches/ruby_2_4/lib/erb.rb branches/ruby_2_4/test/erb/test_erb.rb branches/ruby_2_4/version.h Index: ruby_2_4/lib/erb.rb =================================================================== --- ruby_2_4/lib/erb.rb (revision 59300) +++ ruby_2_4/lib/erb.rb (revision 59301) @@ -389,13 +389,13 @@ class ERB https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/erb.rb#L389 @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 @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 @@ -441,7 +441,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/erb.rb#L441 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 @@ -479,7 +479,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/ruby_2_4/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 == '-%>' @@ -542,7 +542,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/erb.rb#L542 yield('<%') elsif elem == '-%>' yield('%>') - yield(:cr) if scanner.scan(/(\n|\z)/) + yield(:cr) if scanner.scan(/(\r?\n|\z)/) else yield(elem) end Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 59300) +++ ruby_2_4/version.h (revision 59301) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.2" #define RUBY_RELEASE_DATE "2017-07-10" -#define RUBY_PATCHLEVEL 141 +#define RUBY_PATCHLEVEL 142 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 7 Index: ruby_2_4/test/erb/test_erb.rb =================================================================== --- ruby_2_4/test/erb/test_erb.rb (revision 59300) +++ ruby_2_4/test/erb/test_erb.rb (revision 59301) @@ -197,9 +197,28 @@ EOS https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/erb/test_erb.rb#L197 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) + + 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: ruby_2_4 =================================================================== --- ruby_2_4 (revision 59300) +++ ruby_2_4 (revision 59301) Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r58825-58826 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/