From 34b19050b3894d3e6e072f68c112711696dc1c41 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 11 Jun 2011 09:02:11 +0000 Subject: [PATCH] * io.c (io_getc): should be 7bit if ascii. fixes #4557 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ io.c | 2 +- test/ruby/test_io_m17n.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 55a42519b6..a856b4deee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Jun 11 18:02:09 2011 Nobuyoshi Nakada + + * io.c (io_getc): should be 7bit if ascii. fixes #4557 + Sat Jun 11 16:52:16 2011 Nobuyoshi Nakada * numeric.c (rb_enc_uint_chr): fix message format. Bug#4869 diff --git a/io.c b/io.c index 50892e83e6..3618ac2321 100644 --- a/io.c +++ b/io.c @@ -2887,7 +2887,7 @@ io_getc(rb_io_t *fptr, rb_encoding *enc) } else { io_shift_cbuf(fptr, MBCLEN_CHARFOUND_LEN(r), &str); - cr = ENC_CODERANGE_VALID; + cr = ISASCII(r) ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID; } str = io_enc_str(str, fptr); ENC_CODERANGE_SET(str, cr); diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index 86d45a50ae..091b04a5af 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -2060,5 +2060,14 @@ EOT r.close end) end + + def test_getc_ascii_only + bug4557 = '[ruby-core:35630]' + c = with_tmpdir { + open("a", "wb") {|f| f.puts "a"} + open("a", "rt") {|f| f.getc} + } + assert(c.ascii_only?, "should be ascii_only #{bug4557}") + end end