ruby-changes:49465
From: naruse <ko1@a...>
Date: Thu, 4 Jan 2018 03:11:52 +0900 (JST)
Subject: [ruby-changes:49465] naruse:r61581 (ruby_2_5): merge revision(s) 61497: [Backport #14243]
naruse 2018-01-04 03:11:47 +0900 (Thu, 04 Jan 2018) New Revision: 61581 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61581 Log: merge revision(s) 61497: [Backport #14243] erb.rb: preserve the behavior for invalid syntax comment. Fix regression at r58948. I even don't want to deprecate it because deprecation needs to lex all embedded Ruby script using Ripper and it would be slow. So Let me just keep this behavior of Ruby 2.4. No change is the best compatibility. This commit stopped using String#-@ because it's harmful for "ambiguous first argument" warning if we really want to maintain this behavior. [Bug #14243] Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/lib/erb.rb branches/ruby_2_5/test/erb/test_erb.rb branches/ruby_2_5/version.h Index: ruby_2_5/test/erb/test_erb.rb =================================================================== --- ruby_2_5/test/erb/test_erb.rb (revision 61580) +++ ruby_2_5/test/erb/test_erb.rb (revision 61581) @@ -622,6 +622,13 @@ EOS https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/erb/test_erb.rb#L622 erb = @erb.new("<%= 1 %>") assert_raise(TypeError) { erb.result_with_hash({ 1 => "1" }) } end + + # Bug#14243 + def test_half_working_comment_backward_compatibility + assert_nothing_raised do + @erb.new("<% # comment %>\n").result + end + end end class TestERBCoreWOStrScan < TestERBCore Index: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 61580) +++ ruby_2_5/version.h (revision 61581) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.0" #define RUBY_RELEASE_DATE "2018-01-04" -#define RUBY_PATCHLEVEL 3 +#define RUBY_PATCHLEVEL 4 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 1 Index: ruby_2_5/lib/erb.rb =================================================================== --- ruby_2_5/lib/erb.rb (revision 61580) +++ ruby_2_5/lib/erb.rb (revision 61581) @@ -291,7 +291,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/erb.rb#L291 # <i>Generates</i>: # # #coding:UTF-8 - # _erbout=+''; _erbout.<<(-"Got "); _erbout.<<(( obj ).to_s); _erbout.<<(-"!\n"); _erbout + # _erbout=+''; _erbout.<< "Got ".freeze; _erbout.<<(( obj ).to_s); _erbout.<< "!\n".freeze; _erbout # # By default the output is sent to the print method. For example: # @@ -302,7 +302,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/erb.rb#L302 # <i>Generates</i>: # # #coding:UTF-8 - # print(-"Got "); print(( obj ).to_s); print(-"!\n") + # print "Got ".freeze; print(( obj ).to_s); print "!\n".freeze # # == Evaluation # @@ -576,17 +576,8 @@ class ERB https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/erb.rb#L576 end end - def content_dump(s) # :nodoc: - n = s.count("\n") - if n > 0 - s.dump << "\n" * n - else - s.dump - end - end - def add_put_cmd(out, content) - out.push("#{@put_cmd}(-#{content_dump(content)})") + out.push("#{@put_cmd} #{content.dump}.freeze#{"\n" * content.count("\n")}") end def add_insert_cmd(out, content) @@ -668,7 +659,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/erb.rb#L659 when '<%=' add_insert_cmd(out, content) when '<%#' - # out.push("# #{content_dump(content)}") + # commented out end end Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 61580) +++ ruby_2_5 (revision 61581) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r61497 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/