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

ruby-changes:39739

From: nobu <ko1@a...>
Date: Thu, 10 Sep 2015 22:49:15 +0900 (JST)
Subject: [ruby-changes:39739] nobu:r51820 (trunk): parse.y: keep literal encoding

nobu	2015-09-10 22:48:51 +0900 (Thu, 10 Sep 2015)

  New Revision: 51820

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

  Log:
    parse.y: keep literal encoding
    
    * parse.y (literal_concat_gen, evstr2dstr_gen): keep literal
      encoding beginning with an interpolation same as the source file
      encoding.  [ruby-core:70703] [Bug #11519]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_literal.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51819)
+++ ChangeLog	(revision 51820)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Sep 10 22:48:49 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (literal_concat_gen, evstr2dstr_gen): keep literal
+	  encoding beginning with an interpolation same as the source file
+	  encoding.  [ruby-core:70703] [Bug #11519]
+
 Thu Sep 10 22:15:51 2015  Joe Rafaniello  <jrafanie@r...>
 
 	* process.c (rb_f_spawn): Be more specific regarding "other
Index: parse.y
===================================================================
--- parse.y	(revision 51819)
+++ parse.y	(revision 51820)
@@ -8725,7 +8725,7 @@ literal_concat_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L8725
 
     htype = nd_type(head);
     if (htype == NODE_EVSTR) {
-	NODE *node = NEW_DSTR(Qnil);
+	NODE *node = NEW_DSTR(STR_NEW0());
 	head = list_append(node, head);
 	htype = NODE_DSTR;
     }
@@ -8798,7 +8798,7 @@ static NODE * https://github.com/ruby/ruby/blob/trunk/parse.y#L8798
 evstr2dstr_gen(struct parser_params *parser, NODE *node)
 {
     if (nd_type(node) == NODE_EVSTR) {
-	node = list_append(NEW_DSTR(Qnil), node);
+	node = list_append(NEW_DSTR(STR_NEW0()), node);
     }
     return node;
 }
Index: test/ruby/test_literal.rb
===================================================================
--- test/ruby/test_literal.rb	(revision 51819)
+++ test/ruby/test_literal.rb	(revision 51820)
@@ -102,6 +102,15 @@ class TestRubyLiteral < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_literal.rb#L102
     assert_equal('FooBar', b, 'r3842')
   end
 
+  def test_dstring_encoding
+    bug11519 = '[ruby-core:70703] [Bug #11519]'
+    ['"foo#{}"', '"#{}foo"', '"#{}"'].each do |code|
+      a = eval("#-*- coding: utf-8 -*-\n#{code}")
+      assert_equal(Encoding::UTF_8, a.encoding,
+                   proc{"#{bug11519}: #{code}.encoding"})
+    end
+  end
+
   def test_dsymbol
     assert_equal :a3c, :"a#{1+2}c"
   end

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

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