szn

Bug 61 — cfg.zig — stripInlineComment doesn’t handle escaped quotes in value strings

61. cfg.zig — stripInlineComment doesn’t handle escaped quotes in value strings

File: src/cfg.zig:149–162 Severity: LOW Status: ✅ FIXED — Rewrote stripInlineComment using an escape-aware character-by-character scanner to correctly parse comment hash characters.

fn stripInlineComment(line: []const u8) []const u8 {
    if (std.mem.indexOfScalar(u8, line, '#')) |pos| {
        const before = line[0..pos];
        var in_quote = false;
        for (before) |c| {
            if (c == '"') in_quote = !in_quote;
        }
        if (!in_quote) return std.mem.trim(u8, before, " \t");
    }
    return line;
}

Quoted strings with an escaped quote inside (e.g. set -g something "value \"with\" hash # comment") would toggle in_quote on each \" as well as real ", miscounting and treating the # as a comment start. A proper escape-aware parser would skip \" pairs.