-dmain.zig joins argv with unquoted spaces and strips -d from non-new-session commandsSeverity: CRITICAL
Status: ✅ RESOLVED
Files: src/main.zig:352-375
When szn is invoked from the CLI with a subcommand (e.g. szn send-keys "hello world", szn set -g status-left "[#S] ", szn new-window -n "my win", szn paste-buffer -d), src/main.zig:352-375 constructs cmd_str:
var total_len: usize = 0;
var count: usize = 0;
for (args[1..]) |arg| {
if (std.mem.eql(u8, arg, "-d") or std.mem.eql(u8, arg, "--detached")) continue;
total_len += arg.len;
count += 1;
}
if (count > 1) total_len += count - 1;
const cmd_buf = try gpa.alloc(u8, total_len);
var pos: usize = 0;
var idx: usize = 0;
for (args[1..]) |arg| {
if (std.mem.eql(u8, arg, "-d") or std.mem.eql(u8, arg, "--detached")) continue;
if (idx > 0) {
cmd_buf[pos] = ' ';
pos += 1;
}
@memcpy(cmd_buf[pos .. pos + arg.len], arg);
pos += arg.len;
idx += 1;
}
This causes two user-facing bugs:
Quoted / whitespace-containing CLI arguments are split or corrupted:
The shell removes quotes before populating argv, so "hello world" arrives as the slice "hello world" and "[#S] " arrives as "[#S] ". Joining args[1..] with ' ' produces send-keys hello world (which sends "hello" and "world" as separate tokens) and set -g status-left [#S] (which loses the trailing space when cmd.parse tokenizes the unquoted string). Empty arguments ("") disappear completely.
-d / --detached is stripped from ALL commands, not just new-session:
Because the if (std.mem.eql(u8, arg, "-d") ...) filter is not gated on is_new_cmd, running szn paste-buffer -d (where -d means delete the paste buffer after pasting, handled in src/cmd/cmd.zig:518) silently drops -d before sending paste-buffer to the server.
-d / --detached in main.zig when is_new_cmd is true (or let cmdNewSession accept and ignore -d / --detached directly).args[1..] (for idx >= 1, i.e. arguments after the command name), wrap any argument that is empty or contains whitespace, '\"', '\\', or '\'' in double quotes with \" and \\ escaped so cmd.parse reconstructs the exact argv tokens on the server.