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

ruby-changes:16609

From: yugui <ko1@a...>
Date: Sat, 10 Jul 2010 13:06:16 +0900 (JST)
Subject: [ruby-changes:16609] Ruby:r28603 (ruby_1_9_2): merges r28537 and r28555 from trunk into ruby_1_9_2.

yugui	2010-07-10 13:05:59 +0900 (Sat, 10 Jul 2010)

  New Revision: 28603

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

  Log:
    merges r28537 and r28555 from trunk into ruby_1_9_2.
    --
    * io.c (swallow, prepare_getline_args, rb_io_getline_1): fix for
      paragraph mode reading in non-ascii-compatible encoding.
      [ruby-dev:41803]
    --
    * test/ruby/test_io_m17n.rb (test_textmode_paragraph_nonasciicompat): should
      match the modes of both end of pipe as text mode.
    
    * test/ruby/test_io_m17n.rb (test_binmode_paragraph_nonasciicompat): new test
      for binmode.

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

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 28602)
+++ ruby_1_9_2/ChangeLog	(revision 28603)
@@ -1,3 +1,9 @@
+Sun Jul  4 17:13:14 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (swallow, prepare_getline_args, rb_io_getline_1): fix for
+	  paragraph mode reading in non-ascii-compatible encoding.
+	  [ruby-dev:41803]
+
 Sat Jul 10 11:41:54 2010  Yuki Sonoda (Yugui)  <yugui@y...>
 
 	* test/psych/test_date_time.rb (TestDateTime#test_round_trip_with_offset):
Index: ruby_1_9_2/io.c
===================================================================
--- ruby_1_9_2/io.c	(revision 28602)
+++ ruby_1_9_2/io.c	(revision 28603)
@@ -2289,8 +2289,9 @@
 	    while ((cnt = READ_CHAR_PENDING_COUNT(fptr)) > 0) {
 		const char *p = READ_CHAR_PENDING_PTR(fptr);
 		int i;
-		if (needconv) {
+		if (!needconv) {
 		    if (*p != term) return TRUE;
+		    i = (int)cnt;
 		    while (--i && *++p == term);
 		}
 		else {
@@ -2406,7 +2407,7 @@
 	enc_io = io_read_encoding(fptr);
 	if (enc_io != enc_rs &&
 	    (rb_enc_str_coderange(rs) != ENC_CODERANGE_7BIT ||
-	     !rb_enc_asciicompat(enc_io))) {
+	     (RSTRING_LEN(rs) > 0 && !rb_enc_asciicompat(enc_io)))) {
             if (rs == rb_default_rs) {
                 rs = rb_enc_str_new(0, 0, enc_io);
                 rb_str_buf_cat_ascii(rs, "\n");
@@ -2450,6 +2451,8 @@
 	int rspara = 0;
         int extra_limit = 16;
 
+        enc = io_read_encoding(fptr);
+
 	if (!NIL_P(rs)) {
 	    rslen = RSTRING_LEN(rs);
 	    if (rslen == 0) {
@@ -2458,6 +2461,13 @@
 		rspara = 1;
 		swallow(fptr, '\n');
 		rs = 0;
+		if (!rb_enc_asciicompat(enc)) {
+		    rs = rb_usascii_str_new(rsptr, rslen);
+		    rs = rb_str_encode(rs, rb_enc_from_encoding(enc), 0, Qnil);
+		    OBJ_FREEZE(rs);
+		    rsptr = RSTRING_PTR(rs);
+		    rslen = RSTRING_LEN(rs);
+		}
 	    }
 	    else {
 		rsptr = RSTRING_PTR(rs);
@@ -2466,7 +2476,6 @@
 	}
 
 	/* MS - Optimisation */
-        enc = io_read_encoding(fptr);
 	while ((c = appendline(fptr, newline, &str, &limit)) != EOF) {
             const char *s, *p, *pp, *e;
 
Index: ruby_1_9_2/test/ruby/test_io_m17n.rb
===================================================================
--- ruby_1_9_2/test/ruby/test_io_m17n.rb	(revision 28602)
+++ ruby_1_9_2/test/ruby/test_io_m17n.rb	(revision 28603)
@@ -1806,5 +1806,32 @@
     end
   end
 
+  def test_textmode_paragraph_nonasciicompat
+    bug3534 = ['[ruby-dev:41803]', '[Bug #3534]']
+    r, w = IO.pipe
+    [Encoding::UTF_32BE, Encoding::UTF_32LE,
+     Encoding::UTF_16BE, Encoding::UTF_16LE,
+     Encoding::UTF_8].each do |e|
+      r.set_encoding(Encoding::US_ASCII, e)
+      w.print(bug3534[0], "\n\n\n\n", bug3534[1], "\n")
+      assert_equal((bug3534[0]+"\n\n").encode(e), r.gets(""), bug3534[0])
+      assert_equal((bug3534[1]+"\n").encode(e), r.gets(), bug3534[1])
+    end
+  end
+
+  def test_binmode_paragraph_nonasciicompat
+    bug3534 = ['[ruby-dev:41803]', '[Bug #3534]']
+    r, w = IO.pipe
+    r.binmode
+    w.binmode
+    [Encoding::UTF_32BE, Encoding::UTF_32LE,
+     Encoding::UTF_16BE, Encoding::UTF_16LE,
+     Encoding::UTF_8].each do |e|
+      r.set_encoding(Encoding::US_ASCII, e)
+      w.print(bug3534[0], "\n\n\n\n", bug3534[1], "\n")
+      assert_equal((bug3534[0]+"\n\n").encode(e), r.gets(""), bug3534[0])
+      assert_equal((bug3534[1]+"\n").encode(e), r.gets(), bug3534[1])
+    end
+  end
 end
 

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

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