mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (io_unread): fix IO#pos with mode 'r' bug on Windows.
If the end of reading buffer is CR, io_unread() needs to unread one more byte. [ruby-core:44874] [Bug #6401] * test/ruby/test_io_m17n.rb (TestIO_M17N#test_pos_with_buffer_end_cr): add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c45d780b83
commit
7e134cf71e
3 changed files with 32 additions and 0 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Tue May 8 20:44:46 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
|
||||
|
||||
* io.c (io_unread): fix IO#pos with mode 'r' bug on Windows.
|
||||
If the end of reading buffer is CR, io_unread() needs to unread one
|
||||
more byte.
|
||||
[ruby-core:44874] [Bug #6401]
|
||||
|
||||
* test/ruby/test_io_m17n.rb (TestIO_M17N#test_pos_with_buffer_end_cr):
|
||||
add a test for above.
|
||||
|
||||
Tue May 8 13:38:17 2012 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
|
||||
|
||||
* ext/date/date_core.c: improving introduction in Date/DateTime
|
||||
|
|
6
io.c
6
io.c
|
@ -457,6 +457,12 @@ io_unread(rb_io_t *fptr)
|
|||
/* add extra offset for removed '\r' in rbuf */
|
||||
extra_max = (long)(pos - fptr->rbuf.len);
|
||||
p = fptr->rbuf.ptr + fptr->rbuf.off;
|
||||
|
||||
/* if the end of rbuf is '\r', rbuf doesn't have '\r' within rbuf.len */
|
||||
if (*(fptr->rbuf.ptr + fptr->rbuf.capa - 1) == '\r') {
|
||||
newlines++;
|
||||
}
|
||||
|
||||
for (i = 0; i < fptr->rbuf.len; i++) {
|
||||
if (*p == '\n') newlines++;
|
||||
if (extra_max == newlines) break;
|
||||
|
|
|
@ -2432,6 +2432,22 @@ EOT
|
|||
}
|
||||
end if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||
|
||||
def test_pos_with_buffer_end_cr
|
||||
bug6401 = '[ruby-core:44874]'
|
||||
with_tmpdir {
|
||||
# Read buffer size is 8191. This generates '\r' at 8191.
|
||||
lines = ["X" * 8187, "X"]
|
||||
generate_file("tmp", lines.join("\r\n") + "\r\n")
|
||||
|
||||
open("tmp", "r") do |f|
|
||||
lines.each do |line|
|
||||
f.pos
|
||||
assert_equal(line, f.readline.chomp, bug6401)
|
||||
end
|
||||
end
|
||||
}
|
||||
end if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||
|
||||
def test_read_crlf_and_eof
|
||||
bug6271 = '[ruby-core:44189]'
|
||||
with_tmpdir {
|
||||
|
|
Loading…
Add table
Reference in a new issue