std.Io.Reader: fix appendRemainingUnlimited

Now it avoids mutating `r` unnecessarily, allowing the `ending` Reader
to work.
This commit is contained in:
Andrew Kelley 2025-08-04 20:27:55 -07:00
parent b757d7f941
commit 18c4a500b6
2 changed files with 7 additions and 3 deletions

View File

@ -367,8 +367,11 @@ pub fn appendRemainingUnlimited(
const buffer_contents = r.buffer[r.seek..r.end];
try list.ensureUnusedCapacity(gpa, buffer_contents.len + bump);
list.appendSliceAssumeCapacity(buffer_contents);
r.seek = 0;
r.end = 0;
// If statement protects `ending`.
if (r.end != 0) {
r.seek = 0;
r.end = 0;
}
// From here, we leave `buffer` empty, appending directly to `list`.
var writer: Writer = .{
.buffer = undefined,

View File

@ -414,7 +414,8 @@ test "general client/server API coverage" {
log.info("{f} {t} {s}", .{ request.head.method, request.head.version, request.head.target });
const gpa = std.testing.allocator;
const body = try (try request.readerExpectContinue(&.{})).allocRemaining(gpa, .unlimited);
const reader = (try request.readerExpectContinue(&.{}));
const body = try reader.allocRemaining(gpa, .unlimited);
defer gpa.free(body);
if (mem.startsWith(u8, request.head.target, "/get")) {