aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-29 02:14:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-29 02:14:36 +0000
commitc55ad90a6ec114014ed7a4188ecc1063a48a7127 (patch)
tree9abe3a8e274fc5acfb8b3bb0090ca70a5cb9cf44
parent1c3a3f47dcbe199903a45539d5246f6ef69b5d25 (diff)
downloadruby-c55ad90a6ec114014ed7a4188ecc1063a48a7127.tar.gz
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--lib/erb.rb6
-rw-r--r--test/erb/test_erb.rb9
3 files changed, 18 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 06e25a7ecd..73371bc898 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Jan 29 11:13:33 2016 Jeremy Evans <code@jeremyevans.net>
+
+ * 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@ruby-lang.org>
* lib/net/http/header.rb: Warn nil variable on HTTP Header.
diff --git a/lib/erb.rb b/lib/erb.rb
index 5223a280ad..2e9fad98b4 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -280,7 +280,7 @@ class ERB
# 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
# <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
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
diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb
index 29fbf97686..97f45af73d 100644
--- a/test/erb/test_erb.rb
+++ b/test/erb/test_erb.rb
@@ -534,6 +534,15 @@ EOS
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