diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-04-28 17:59:40 +0900 |
|---|---|---|
| committer | Hiroshi Mimaki <[email protected]> | 2020-05-07 09:32:46 +0900 |
| commit | 6b839b231971f058656521dc39bd4f27968230c6 (patch) | |
| tree | 3ea028c51527b22ec189dd2d9c0344b48b1735b3 /mrbgems/mruby-io/mrblib/io.rb | |
| parent | 45bd372755171cee72fd547f3295653918231f77 (diff) | |
| download | mruby-6b839b231971f058656521dc39bd4f27968230c6.tar.gz mruby-6b839b231971f058656521dc39bd4f27968230c6.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.rb | 5 |
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 |
