szn

Bug 436 — Command parser has no quote/escape handling; quoted multi-word args mis-tokenize

436. Command parser has no quote/escape handling; quoted multi-word args mis-tokenize

Severity: MEDIUM Status: Fixed

parse splits the raw command line into argv with a bare space tokenizer and no quote or backslash handling:

// src/cmd/cmd.zig:1672-1687
pub fn parse(input: []const u8, allocator: std.mem.Allocator) !CmdArgs {
    var arg_list: std.ArrayList([]const u8) = .empty;
    var it = std.mem.tokenizeScalar(u8, input, ' ');
    while (it.next()) |token| {
        try arg_list.append(allocator, token);
    }
    // ...
}

Problem & Impact

Reference Behavior

tmux’s command parser honors single/double quotes and backslash escapes so that "a b" is a single argument. szn’s parse implements none of this.

Proposed Fix

Replace the space tokenizer with a small argv splitter that tracks quote state (single/double) and processes \ escapes, producing one token per logical argument and stripping the surrounding quotes. Keep min_args/max_args validation as-is.