[前][次][番号順一覧][スレッド一覧]

ruby-changes:41608

From: nobu <ko1@a...>
Date: Fri, 29 Jan 2016 11:13:38 +0900 (JST)
Subject: [ruby-changes:41608] nobu:r53682 (trunk): erb.rb: frozen-string-literal safe

nobu	2016-01-29 11:14:36 +0900 (Fri, 29 Jan 2016)

  New Revision: 53682

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53682

  Log:
    erb.rb: frozen-string-literal safe
    
    * lib/erb.rb (ERB#set_eoutvar): explicitly make mutable string as
      a buffer to make ERB work with --enable-frozen-string-literal.
      [ruby-core:73561] [Bug #12031]

  Modified files:
    trunk/ChangeLog
    trunk/lib/erb.rb
    trunk/test/erb/test_erb.rb
Index: test/erb/test_erb.rb
===================================================================
--- test/erb/test_erb.rb	(revision 53681)
+++ test/erb/test_erb.rb	(revision 53682)
@@ -534,6 +534,15 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L534
     EOS
     assert_equal(ans, extended_erb.new(src).result)
   end
+
+  def test_frozen_string_literal
+    bug12031 = '[ruby-core:73561] [Bug #12031]'
+    e = @erb.new("<%#encoding: us-ascii%>a")
+    e.src.sub!(/\A#(?:-\*-)?(.*)(?:-\*-)?/) {
+      '# -*- \1; frozen-string-literal: true -*-'
+    }
+    assert_equal("a", e.result, bug12031)
+  end
 end
 
 class TestERBCoreWOStrScan < TestERBCore
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53681)
+++ ChangeLog	(revision 53682)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jan 29 11:13:33 2016  Jeremy Evans  <code@j...>
+
+	* lib/erb.rb (ERB#set_eoutvar): explicitly make mutable string as
+	  a buffer to make ERB work with --enable-frozen-string-literal.
+	  [ruby-core:73561] [Bug #12031]
+
 Fri Jan 29 10:44:56 2016  SHIBATA Hiroshi  <hsbt@r...>
 
 	* lib/net/http/header.rb: Warn nil variable on HTTP Header.
Index: lib/erb.rb
===================================================================
--- lib/erb.rb	(revision 53681)
+++ lib/erb.rb	(revision 53682)
@@ -280,7 +280,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L280
   # ERB#src:
   #
   #   compiler = ERB::Compiler.new('<>')
-  #   compiler.pre_cmd    = ["_erbout=''"]
+  #   compiler.pre_cmd    = ["_erbout=String.new"]
   #   compiler.put_cmd    = "_erbout.concat"
   #   compiler.insert_cmd = "_erbout.concat"
   #   compiler.post_cmd   = ["_erbout"]
@@ -291,7 +291,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L291
   # <i>Generates</i>:
   #
   #   #coding:UTF-8
-  #   _erbout=''; _erbout.concat "Got "; _erbout.concat(( obj ).to_s); _erbout.concat "!\n"; _erbout
+  #   _erbout=String.new; _erbout.concat "Got "; _erbout.concat(( obj ).to_s); _erbout.concat "!\n"; _erbout
   #
   # By default the output is sent to the print method.  For example:
   #
@@ -860,7 +860,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L860
   def set_eoutvar(compiler, eoutvar = '_erbout')
     compiler.put_cmd = "#{eoutvar}.concat"
     compiler.insert_cmd = "#{eoutvar}.concat"
-    compiler.pre_cmd = ["#{eoutvar} = ''"]
+    compiler.pre_cmd = ["#{eoutvar} = String.new"]
     compiler.post_cmd = ["#{eoutvar}.force_encoding(__ENCODING__)"]
   end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]