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

ruby-changes:7646

From: akr <ko1@a...>
Date: Sat, 6 Sep 2008 07:30:03 +0900 (JST)
Subject: [ruby-changes:7646] Ruby:r19167 (trunk): * transcode.c (rb_econv_open): fail for ASCII incompatible with

akr	2008-09-06 07:27:46 +0900 (Sat, 06 Sep 2008)

  New Revision: 19167

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

  Log:
    * transcode.c (rb_econv_open): fail for ASCII incompatible with
      newline conversion.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_econv.rb
    trunk/transcode.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19166)
+++ ChangeLog	(revision 19167)
@@ -1,3 +1,8 @@
+Sat Sep  6 07:27:00 2008  Tanaka Akira  <akr@f...>
+
+	* transcode.c (rb_econv_open): fail for ASCII incompatible with
+	  newline conversion.
+
 Sat Sep  6 07:24:49 2008  Tanaka Akira  <akr@f...>
 
 	* io.c (rb_io_extract_modeenc): raise an error for ASCII incompatible
Index: test/ruby/test_econv.rb
===================================================================
--- test/ruby/test_econv.rb	(revision 19166)
+++ test/ruby/test_econv.rb	(revision 19167)
@@ -54,6 +54,28 @@
     assert(!encoding_list.include?(name2))
   end
 
+  def test_newline_converter_with_ascii_incompatible
+    assert_raise(Encoding::NoConverter) {
+      Encoding::Converter.new("UTF-8", "UTF-16BE", Encoding::Converter::UNIVERSAL_NEWLINE_DECODER)
+    }
+    assert_raise(Encoding::NoConverter) {
+      Encoding::Converter.new("UTF-16BE", "UTF-8", Encoding::Converter::CRLF_NEWLINE_ENCODER)
+    }
+    assert_raise(Encoding::NoConverter) {
+      Encoding::Converter.new("UTF-16BE", "UTF-8", Encoding::Converter::CR_NEWLINE_ENCODER)
+    }
+
+    assert_nothing_raised {
+      Encoding::Converter.new("UTF-16BE", "UTF-8", Encoding::Converter::UNIVERSAL_NEWLINE_DECODER)
+    }
+    assert_nothing_raised {
+      Encoding::Converter.new("UTF-8", "UTF-16BE", Encoding::Converter::CRLF_NEWLINE_ENCODER)
+    }
+    assert_nothing_raised {
+      Encoding::Converter.new("UTF-8", "UTF-16BE", Encoding::Converter::CR_NEWLINE_ENCODER)
+    }
+  end
+
   def test_get_encoding
     ec = Encoding::Converter.new("UTF-8", "EUC-JP")
     assert_equal(Encoding::UTF_8, ec.source_encoding)
Index: transcode.c
===================================================================
--- transcode.c	(revision 19166)
+++ transcode.c	(revision 19167)
@@ -913,6 +913,19 @@
     }
 
     num_additional = 0;
+
+    if (*sname && (!senc || !rb_enc_asciicompat(senc)) &&
+        (ecflags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER))) {
+        xfree(entries);
+        return NULL;
+    }
+
+    if (*dname && (!denc || !rb_enc_asciicompat(denc)) &&
+        (ecflags & (ECONV_UNIVERSAL_NEWLINE_DECODER))) {
+        xfree(entries);
+        return NULL;
+    }
+
     if ((!*sname || (senc && rb_enc_asciicompat(senc))) &&
         (ecflags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER))) {
         const char *name = (ecflags & ECONV_CRLF_NEWLINE_ENCODER) ? "crlf_newline" : "cr_newline";

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

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