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

ruby-changes:29198

From: nobu <ko1@a...>
Date: Wed, 12 Jun 2013 12:44:59 +0900 (JST)
Subject: [ruby-changes:29198] nobu:r41250 (trunk): io.c: fix 7bit coderange condition

nobu	2013-06-12 12:44:48 +0900 (Wed, 12 Jun 2013)

  New Revision: 41250

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

  Log:
    io.c: fix 7bit coderange condition
    
    * io.c (io_getc): fix 7bit coderange condition, check if ascii read
      data instead of read length. [ruby-core:55444] [Bug #8516]

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41249)
+++ ChangeLog	(revision 41250)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jun 12 12:44:45 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (io_getc): fix 7bit coderange condition, check if ascii read
+	  data instead of read length. [ruby-core:55444] [Bug #8516]
+
 Wed Jun 12 12:35:13 2013  Tanaka Akira  <akr@f...>
 
 	* pack.c (pack_pack): Use rb_integer_pack_2comp.
Index: io.c
===================================================================
--- io.c	(revision 41249)
+++ io.c	(revision 41250)
@@ -3411,7 +3411,11 @@ io_getc(rb_io_t *fptr, rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/io.c#L3411
 	}
 	else {
 	    io_shift_cbuf(fptr, MBCLEN_CHARFOUND_LEN(r), &str);
-	    cr = ISASCII(r) ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID;
+	    cr = ENC_CODERANGE_VALID;
+	    if (MBCLEN_CHARFOUND_LEN(r) == 1 && rb_enc_asciicompat(read_enc) &&
+		ISASCII(RSTRING_PTR(str)[0])) {
+		cr = ENC_CODERANGE_7BIT;
+	    }
 	}
 	str = io_enc_str(str, fptr);
 	ENC_CODERANGE_SET(str, cr);
Index: test/ruby/test_io_m17n.rb
===================================================================
--- test/ruby/test_io_m17n.rb	(revision 41249)
+++ test/ruby/test_io_m17n.rb	(revision 41250)
@@ -2196,7 +2196,17 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L2196
       open("a", "wb") {|f| f.puts "a"}
       open("a", "rt") {|f| f.getc}
     }
-    assert(c.ascii_only?, "should be ascii_only #{bug4557}")
+    assert_predicate(c, :ascii_only?, bug4557)
+  end
+
+  def test_getc_conversion
+    bug8516 = '[ruby-core:55444] [Bug #8516]'
+    c = with_tmpdir {
+      open("a", "wb") {|f| f.putc "\xe1"}
+      open("a", "r:iso-8859-1:utf-8") {|f| f.getc}
+    }
+    assert_not_predicate(c, :ascii_only?, bug8516)
+    assert_equal(1, c.size, bug8516)
   end
 
   def test_default_mode_on_dosish

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

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