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

ruby-changes:23245

From: shirosaki <ko1@a...>
Date: Wed, 11 Apr 2012 21:05:30 +0900 (JST)
Subject: [ruby-changes:23245] shirosaki:r35296 (trunk): * io.c (rb_io_eof): use eof() instead of io_fillbuf(). It's because

shirosaki	2012-04-11 21:05:19 +0900 (Wed, 11 Apr 2012)

  New Revision: 35296

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

  Log:
    * io.c (rb_io_eof): use eof() instead of io_fillbuf(). It's because
      io_unread() doesn't work properly when reading CRLF with read(length)
      and mode 'r'.
      [ruby-core:44189][Bug #6271]
    
    * test/ruby/test_io_m17n.rb (TestIO_M17N#test_read_crlf_and_eof):
      test for above.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35295)
+++ ChangeLog	(revision 35296)
@@ -1,3 +1,13 @@
+Wed Apr 11 20:28:36 2012  Hiroshi Shirosaki  <h.shirosaki@g...>
+
+	* io.c (rb_io_eof): use eof() instead of io_fillbuf(). It's because
+	  io_unread() doesn't work properly when reading CRLF with read(length)
+	  and mode 'r'.
+	  [ruby-core:44189][Bug #6271]
+
+	* test/ruby/test_io_m17n.rb (TestIO_M17N#test_read_crlf_and_eof):
+	  test for above.
+
 Wed Apr 11 07:38:33 2012  Eric Hodel  <drbrain@s...>
 
 	* ext/digest/sha2/lib/sha2.rb (Digest#block_length):  Fixed method name
Index: io.c
===================================================================
--- io.c	(revision 35295)
+++ io.c	(revision 35296)
@@ -1614,6 +1614,11 @@
     if (READ_CHAR_PENDING(fptr)) return Qfalse;
     if (READ_DATA_PENDING(fptr)) return Qfalse;
     READ_CHECK(fptr);
+#if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
+    if (!NEED_READCONV(fptr) && NEED_NEWLINE_DECORATOR_ON_READ(fptr)) {
+	return eof(fptr->fd) ? Qtrue : Qfalse;
+    }
+#endif
     if (io_fillbuf(fptr) < 0) {
 	return Qtrue;
     }
Index: test/ruby/test_io_m17n.rb
===================================================================
--- test/ruby/test_io_m17n.rb	(revision 35295)
+++ test/ruby/test_io_m17n.rb	(revision 35296)
@@ -2430,4 +2430,20 @@
       end
     }
   end if /mswin|mingw/ =~ RUBY_PLATFORM
+
+  def test_read_crlf_and_eof
+    bug6271 = '[ruby-core:44189]'
+    with_tmpdir {
+      str = "a\r\nb\r\nc\r\n"
+      generate_file("tmp", str)
+      open("tmp", "r") do |f|
+        i = 0
+        until f.eof?
+          assert_equal(str[i], f.read(1), bug6271)
+          i += 1
+        end
+        assert_equal(str.size, i, bug6271)
+      end
+    }
+  end if /mswin|mingw/ =~ RUBY_PLATFORM
 end

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

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