summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--io.c2
-rw-r--r--test/ruby/test_io_m17n.rb9
3 files changed, 14 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 55a4251..a856b4d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Jun 11 18:02:09 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (io_getc): should be 7bit if ascii. fixes #4557
+
Sat Jun 11 16:52:16 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* numeric.c (rb_enc_uint_chr): fix message format. Bug#4869
diff --git a/io.c b/io.c
index 50892e8..3618ac2 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 86d45a5..091b04a 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