szn

Bug 512 — capture-pane emits NUL bytes

512. capture-pane writes U+0000 for blank and padding cells instead of a space

Severity: HIGH Status: ✅ FIXED Files: src/cmd/cmd.zig:768-774

Problem

The capture loop encodes every cell’s codepoint directly:

// src/cmd/cmd.zig:768-774
const cell = pane.screen.grid.getCell(x, y);
var utf8_buf: [4]u8 = undefined;
const len = std.unicode.utf8Encode(cell.char, &utf8_buf) catch blk: {
    utf8_buf[0] = ' ';
    break :blk 1;
};
server.response_buf.appendSlice(server.allocator, utf8_buf[0..len]) catch return .err;

The catch branch is unreachable for the case that actually matters, because U+0000 is a valid codepoint: utf8Encode(0) succeeds and returns a single 0x00 byte.

Two classes of cell carry char = 0:

So capture-pane output contains a NUL for every unwritten cell, and each wide character is followed by an extra NUL. Piping the result to a file or another program yields binary garbage; szn capture-pane > file.txt produces a file that is not valid UTF-8 text.

Fix

// src/cmd/cmd.zig — cmdCapturePane
if (cell.is_padding) continue;
const cp: u21 = if (cell.char == 0) ' ' else cell.char;

Two changes to the capture loop:

Regression test

capture-pane emits spaces, not NUL bytes, for blank and padding cells — bug #512 (src/cmd/cmd.zig) writes one wide character (世) into a 20×2 pane, captures it, and asserts:

Verified with the full suite on Zig 0.16.0 and 0.17.0: 1044/1044 passing on both.

Bug #199 established that padding cells are not content in reflow; this applies the same rule to the capture path.