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

ruby-changes:39035

From: nobu <ko1@a...>
Date: Fri, 3 Jul 2015 12:25:39 +0900 (JST)
Subject: [ruby-changes:39035] nobu:r51116 (trunk): transcode.c: empty encoding name

nobu	2015-07-03 12:25:21 +0900 (Fri, 03 Jul 2015)

  New Revision: 51116

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

  Log:
    transcode.c: empty encoding name
    
    * transcode.c (rb_econv_set_replacement): target encoding name can
      be empty now.  [ruby-core:69841] [Bug #11324]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_transcode.rb
    trunk/transcode.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51115)
+++ ChangeLog	(revision 51116)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jul  3 12:25:19 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* transcode.c (rb_econv_set_replacement): target encoding name can
+	  be empty now.  [ruby-core:69841] [Bug #11324]
+
 Fri Jul  3 07:21:06 2015  Eric Wong  <e@8...>
 
 	* benchmark/bm_io_nonblock_noex.rb: new benchmark
Index: test/ruby/test_transcode.rb
===================================================================
--- test/ruby/test_transcode.rb	(revision 51115)
+++ test/ruby/test_transcode.rb	(revision 51116)
@@ -2109,4 +2109,13 @@ class TestTranscode < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_transcode.rb#L2109
       assert_equal([expected]*num, result, bug11277)
     end;
   end
+
+  def test_universal_newline
+    bug11324 = '[ruby-core:69841] [Bug #11324]'
+    usascii = Encoding::US_ASCII
+    s = "A\nB\r\nC".force_encoding(usascii)
+    assert_equal("A\nB\nC", s.encode(usascii, universal_newline: true), bug11324)
+    assert_equal("A\nB\nC", s.encode(usascii, universal_newline: true, undef: :replace), bug11324)
+    assert_equal("A\nB\nC", s.encode(usascii, universal_newline: true, undef: :replace, replace: ''), bug11324)
+  end
 end
Index: transcode.c
===================================================================
--- transcode.c	(revision 51115)
+++ transcode.c	(revision 51116)
@@ -2199,7 +2199,7 @@ rb_econv_set_replacement(rb_econv_t *ec, https://github.com/ruby/ruby/blob/trunk/transcode.c#L2199
 
     encname2 = rb_econv_encoding_to_insert_output(ec);
 
-    if (encoding_equal(encname, encname2)) {
+    if (!*encname2 || encoding_equal(encname, encname2)) {
         str2 = xmalloc(len);
         MEMCPY(str2, str, unsigned char, len); /* xxx: str may be invalid */
         len2 = len;

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

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