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

ruby-changes:13569

From: nobu <ko1@a...>
Date: Thu, 15 Oct 2009 15:14:28 +0900 (JST)
Subject: [ruby-changes:13569] Ruby:r25350 (trunk): * io.c (io_encoding_set): get rid of parsing non-ascii string, and

nobu	2009-10-15 15:14:16 +0900 (Thu, 15 Oct 2009)

  New Revision: 25350

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

  Log:
    * io.c (io_encoding_set): get rid of parsing non-ascii string, and
      refine messages for invalid name encoding.

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/ruby/test_io_m17n.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25349)
+++ ChangeLog	(revision 25350)
@@ -1,5 +1,8 @@
-Thu Oct 15 14:57:58 2009  Nobuyoshi Nakada  <nobu@r...>
+Thu Oct 15 15:14:15 2009  Nobuyoshi Nakada  <nobu@r...>
 
+	* io.c (io_encoding_set): get rid of parsing non-ascii string, and
+	  refine messages for invalid name encoding.
+
 	* io.c (io_reopen): unread current buffer before telling the
 	  position, for the case of reopening same file.  [ruby-dev:39479]
 
Index: io.c
===================================================================
--- io.c	(revision 25349)
+++ io.c	(revision 25350)
@@ -7500,8 +7500,7 @@
 	enc2 = rb_to_encoding(v1);
 	tmp = rb_check_string_type(v2);
 	if (!NIL_P(tmp)) {
-	    char *p = StringValueCStr(tmp);
-	    if (*p == '-' && *(p+1) == '\0') {
+	    if (RSTRING_LEN(tmp) == 1 && RSTRING_PTR(tmp)[0] == '-') {
 		/* Special case - "-" => no transcoding */
 		enc = enc2;
 		enc2 = NULL;
@@ -7526,8 +7525,8 @@
 	}
 	else {
 	    tmp = rb_check_string_type(v1);
-	    if (!NIL_P(tmp)) {
-                parse_mode_enc(StringValueCStr(tmp), &enc, &enc2);
+	    if (!NIL_P(tmp) && rb_enc_asciicompat(rb_enc_get(tmp))) {
+                parse_mode_enc(RSTRING_PTR(tmp), &enc, &enc2);
                 ecflags = rb_econv_prepare_opts(opt, &ecopts);
 	    }
 	    else {
Index: test/ruby/test_io_m17n.rb
===================================================================
--- test/ruby/test_io_m17n.rb	(revision 25349)
+++ test/ruby/test_io_m17n.rb	(revision 25350)
@@ -220,33 +220,27 @@
   end
 
   def test_s_pipe_invalid
-    r, w = IO.pipe("utf-8", "euc-jp", :invalid=>:replace)
-    w << "\x80"
-    w.close
-    assert_equal("?", r.read)
-  ensure
-    r.close if r && !r.closed?
-    w.close if w && !w.closed?
+    with_pipe("utf-8", "euc-jp", :invalid=>:replace) {|r, w|
+      w << "\x80"
+      w.close
+      assert_equal("?", r.read)
+    }
   end
 
   def test_s_pipe_undef
-    r, w = IO.pipe("utf-8:euc-jp", :undef=>:replace)
-    w << "\ufffd"
-    w.close
-    assert_equal("?", r.read)
-  ensure
-    r.close if r && !r.closed?
-    w.close if w && !w.closed?
+    with_pipe("utf-8:euc-jp", :undef=>:replace) {|r, w|
+      w << "\ufffd"
+      w.close
+      assert_equal("?", r.read)
+    }
   end
 
   def test_s_pipe_undef_replace_string
-    r, w = IO.pipe("utf-8:euc-jp", :undef=>:replace, :replace=>"X")
-    w << "\ufffd"
-    w.close
-    assert_equal("X", r.read)
-  ensure
-    r.close if r && !r.closed?
-    w.close if w && !w.closed?
+    with_pipe("utf-8:euc-jp", :undef=>:replace, :replace=>"X") {|r, w|
+      w << "\ufffd"
+      w.close
+      assert_equal("X", r.read)
+    }
   end
 
   def test_dup
@@ -572,6 +566,11 @@
       assert_equal(eucjp, r.read)
     }
 
+    e = assert_raise(ArgumentError) {with_pipe("UTF-8", "UTF-8".encode("UTF-32BE")) {}}
+    assert_match(/invalid name encoding/, e.message)
+    e = assert_raise(ArgumentError) {with_pipe("UTF-8".encode("UTF-32BE")) {}}
+    assert_match(/invalid name encoding/, e.message)
+
     ENCS.each {|enc|
       with_pipe(enc) {|r, w|
         w << "\xc2\xa1"

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

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