diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-11 13:37:29 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-11 18:47:39 +0900 |
| commit | 8c90b5fc6a84c2524c6b7c3bf8920790b00d7431 (patch) | |
| tree | 098fef103c830996acd0990905a52ce026b67521 | |
| parent | ec3aeede20a8287e656866a2d4545bcd23baebf8 (diff) | |
| download | mruby-8c90b5fc6a84c2524c6b7c3bf8920790b00d7431.tar.gz mruby-8c90b5fc6a84c2524c6b7c3bf8920790b00d7431.zip | |
Fixed `length` for IO should be in bytes, not in characters; #4696
E.g. `io.read(5)` should read 5 byte string, not 5 characters.
| -rw-r--r-- | mrbgems/mruby-io/mrblib/io.rb | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb index 6211bf15f..f3c4de6fd 100644 --- a/mrbgems/mruby-io/mrblib/io.rb +++ b/mrbgems/mruby-io/mrblib/io.rb @@ -207,9 +207,9 @@ class IO end if length - consume = (length <= @buf.size) ? length : @buf.size - array.push @buf[0, consume] - @buf = @buf[consume, @buf.size - consume] + consume = (length <= @buf.bytesize) ? length : @buf.bytesize + array.push @buf.byteslice(0, consume) + @buf = @buf.byteslice(consume, @buf.bytesize - consume) length -= consume break if length == 0 else @@ -254,14 +254,14 @@ class IO break end - if limit && limit <= @buf.size - array.push @buf[0, limit] - @buf = @buf[limit, @buf.size - limit] + if limit && limit <= @buf.bytesize + array.push @buf.byteslice(0, limit) + @buf = @buf.byteslice(limit, @buf.bytesize - limit) break elsif idx = @buf.index(rs) - len = idx + rs.size - array.push @buf[0, len] - @buf = @buf[len, @buf.size - len] + len = idx + rs.bytesize + array.push @buf.byteslice(0, len) + @buf = @buf.byteslice(len, @buf.bytesize - len) break else array.push @buf @@ -284,8 +284,8 @@ class IO def readchar _read_buf - c = @buf[0] - @buf = @buf[1, @buf.size] + c = @buf.byteslice(0,1) + @buf = @buf.byteslice(1, @buf.bytesize) c end |
