Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -4499,10 +4499,11 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
gzreader_skip_linebreaks(gz);
}

while (ZSTREAM_BUF_FILLED(&gz->z) < rslen) {
rb_len_t minlen = (limit > 0 && limit < rslen) ? limit : rslen;
while (ZSTREAM_BUF_FILLED(&gz->z) < minlen) {
if (ZSTREAM_IS_FINISHED(&gz->z)) {
if (ZSTREAM_BUF_FILLED(&gz->z) > 0) gz->lineno++;
return gzfile_read(gz, rslen, Qnil);
return gzfile_read(gz, minlen, Qnil);
}
gzfile_read_more(gz, Qnil);
}
Expand All @@ -4511,6 +4512,10 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
n = rslen;
for (;;) {
rb_len_t filled;
if (limit > 0 && limit < rslen) {
Comment thread
mame marked this conversation as resolved.
Resolved
n = limit;
break;
}
if (n > ZSTREAM_BUF_FILLED(&gz->z)) {
if (ZSTREAM_IS_FINISHED(&gz->z)) break;
gzfile_read_more(gz, Qnil);
Expand Down
13 changes: 13 additions & 0 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,19 @@ def test_gets2
}
end

def test_gets_limit_shorter_than_separator
gz = Zlib::GzipReader.new(StringIO.new(Zlib.gzip("abcd")))
assert_equal("a", gz.gets("xyz", 1))
assert_equal("bc", gz.gets("xyz", 2))
assert_equal("d", gz.gets("xyz", 2))
assert_nil(gz.gets("xyz", 2))

gz = Zlib::GzipReader.new(StringIO.new(Zlib.gzip("ab")))
assert_equal("a", gz.gets("xyz", 1))
assert_equal("b", gz.gets("xyz", 1))
assert_nil(gz.gets("xyz", 1))
end

def test_readline
Tempfile.create("test_zlib_gzip_reader_readline") {|t|
t.close
Expand Down
Loading