summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-io/mrblib/io.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-04-28 17:59:40 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-04-28 18:07:17 +0900
commit8627157298cb1443bd8562a8fc0740acfb018974 (patch)
treea262e9735d2ce414616a4492147776735dd44b75 /mrbgems/mruby-io/mrblib/io.rb
parentb87268f130c4a29f4be4172409dbe12cddb4e2f9 (diff)
downloadmruby-8627157298cb1443bd8562a8fc0740acfb018974.tar.gz
mruby-8627157298cb1443bd8562a8fc0740acfb018974.zip
Fix `IO#readchar` to return broken UTF-8 rather than `EOF` error.
The behavior is different from CRuby, but we believe this is a right behavior for mruby, which only supports either ASCII or UTF-8 exclusively; fix #4983, ref #4982 ``` $ printf '\xe3\x81' | ruby -e 'p STDIN.readchar' "\xE3\x81" ``` ``` $ printf '\xe3\x81' | mruby -e 'p STDIN.readchar' "\xE3" ```
Diffstat (limited to 'mrbgems/mruby-io/mrblib/io.rb')
-rw-r--r--mrbgems/mruby-io/mrblib/io.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb
index e43b81004..e597db886 100644
--- a/mrbgems/mruby-io/mrblib/io.rb
+++ b/mrbgems/mruby-io/mrblib/io.rb
@@ -284,15 +284,14 @@ class IO
def readchar
_read_buf
_readchar(@buf)
-# c = @buf[0]
-# @buf[0] = ""
-# c
end
def getc
begin
readchar
rescue EOFError
+ c = @buf[0]
+ @buf[0,1]="" if c
nil
end
end