ruby-changes:48624
From: k0kubun <ko1@a...>
Date: Fri, 10 Nov 2017 22:59:05 +0900 (JST)
Subject: [ruby-changes:48624] k0kubun:r60739 (trunk): bin/erb: change template file encoding to UTF-8
k0kubun 2017-11-10 22:59:01 +0900 (Fri, 10 Nov 2017) New Revision: 60739 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60739 Log: bin/erb: change template file encoding to UTF-8 Unlike Ruby source file encoding (script encoding) whose default is changed to UTF-8 in Ruby 2.0 (Feature #6679), template's file encoding given to erb(1) has been ASCII-8BIT since ERB supports m17n at r21170. Like Ruby source file encoding, erb template file encoding should be UTF-8 in Ruby 2. [Bug #14095] [ruby-core:83708] Modified files: trunk/NEWS trunk/bin/erb trunk/test/erb/test_erb_command.rb Index: NEWS =================================================================== --- NEWS (revision 60738) +++ NEWS (revision 60739) @@ -143,6 +143,8 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L143 * ERB * Add ERB#result_with_hash to render a template with local variables passed with a Hash object. [Feature #8631] + * Default template file encoding is changed from ASCII-8BIT to UTF-8 in erb + command. [Bug #14095] * Carriage returns are changed to be trimmed properly if trim_mode is specified and used. Duplicated newlines will be removed on Windows. [Bug #5339] [Bug #11464] Index: bin/erb =================================================================== --- bin/erb (revision 60738) +++ bin/erb (revision 60739) @@ -122,7 +122,7 @@ EOU https://github.com/ruby/ruby/blob/trunk/bin/erb#L122 exit 1 end - $<.set_encoding(Encoding::ASCII_8BIT, nil) + $<.set_encoding(Encoding::UTF_8, nil) src = $<.read filename = $FILENAME exit 2 unless src Index: test/erb/test_erb_command.rb =================================================================== --- test/erb/test_erb_command.rb (revision 60738) +++ test/erb/test_erb_command.rb (revision 60739) @@ -9,4 +9,10 @@ class TestErbCommand < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb_command.rb#L9 "var=hoge"], "<%=var%>", ["hoge"]) end + + def test_template_file_encoding + assert_in_out_err(["-w", + File.expand_path("../../../bin/erb", __FILE__)], + "<%=''.encoding.to_s%>", ["UTF-8"]) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/