summaryrefslogtreecommitdiff
path: root/core/Stream.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 17:50:13 -0300
committerGabriel Schneider <[email protected]>2026-11-23 17:58:08 -0300
commit4eb608b0c1f231005237b0f57283d22bfccee0a9 (patch)
treea04992918515c2dbdea0837c3de5d854ac65d5bf /core/Stream.zig
parentfcc08ec6ceb9af11aeda8489cef0d4085878ef48 (diff)
downloadpardes-4eb608b0c1f231005237b0f57283d22bfccee0a9.tar.gz
pardes-4eb608b0c1f231005237b0f57283d22bfccee0a9.zip
a file's name in a row is written as git writes an unusual one, and read back so: a newline in a name no longer makes a row of its own: the Grep worker wrote `path:line:col-end code` with the name as it is (core/Stream.zig `row`, and Find's `file`), so a file named `a\nb:1:1` holding a hit made two rows, `a` (no place, passed over) and a hit in a file `b` at line 1, which a crafted name can point anywhere with any text (the test below on the base: the one hit's name `b`); the query pane's rows the same (a name with a newline was two lines of the pane's text over one row's metadata); and a name with a `:` and digits in it read as another file at a line (`a:5:b.txt:3`); THE RULE, one for every row that names a file: git's quote_c_style, `look.quoted`: a name holding a control byte, a `"`, a `\` or a `:` is written in double quotes with `\n \t \r \" \\` and `\ooo` for the other control bytes, any other name as it is; WRITTEN by the worker (Stream `row`, `file`), the query pane's rows (Query: a Grep's, a language server's, a pane's places: the name `lookPath` gives, quoted), the patch view's labels (hunks.zig `flush`); READ by `look.parsePathLine`, which takes a `"`-led word whole to its closing quote as the path (its `:` its own; the place after it as ever), Query `take` (the name unquoted, `look.unquoted`, into the Found it opens) and Find's rows (the name a row shows opens the file it names); a B3 on a quoted row whose name has an escape finds the escaped text and misses (no file has it): a miss, never another file; the patch view's names come from the diff, where git quotes the same way (diff.zig `cutPath` keeps the inside), and Find's rows show the name as the worker wrote it; tests: core/Stream.zig "a file named `a\nb:1:1` is one Grep row and one Find name, its own, for the walk and rg; a row is a line" (fails on the base), core/look.zig "a file's name written as a row writes it reads back whole: ..."; core-test Debug 953/1119 (166 skipped)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Stream.zig')
-rw-r--r--core/Stream.zig51
1 files changed, 49 insertions, 2 deletions
diff --git a/core/Stream.zig b/core/Stream.zig
index 7956e4f2..7f9ad012 100644
--- a/core/Stream.zig
+++ b/core/Stream.zig
@@ -832,13 +832,13 @@ const Worker = struct {
const ln = std.mem.trimEnd(u8, raw, " \t\r\n");
var cut = @min(ln.len, 400);
while (cut > 0 and cut < ln.len and ln[cut] & 0xc0 == 0x80) cut -= 1;
- try w.rows.print(w.gpa, "{s}:{d}:{d}{c}{d} {s}\n", .{ path, line, from + 1, config.range_sep, end, ln[0..cut] });
+ try w.rows.print(w.gpa, "{f}:{d}:{d}{c}{d} {s}\n", .{ look.quoted(path), line, from + 1, config.range_sep, end, ln[0..cut] });
w.total += 1;
}
/// A listing's file: its name, relative to the base.
fn file(w: *Worker, path: []const u8) !bool {
- try w.rows.print(w.gpa, "{s}\n", .{path});
+ try w.rows.print(w.gpa, "{f}\n", .{look.quoted(path)});
w.total += 1;
try w.maybeSend();
return w.checkCap();
@@ -1275,6 +1275,53 @@ test "Stream: the listing of files for Find on a worker, a cap of hits stops the
try testing.expectEqual(State.done, p.stream.state);
}
+test "Stream: a file named `a\\nb:1:1` is one Grep row and one Find name, its own, for the walk and rg; a row is a line" {
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var root_buf: [4096]u8 = undefined;
+ // Up to 2026-11-23 its row, `a\nb:1:1:1:1-6 needle`, was two: `a`
+ // (no place) and a hit in a file `b`, line 1, that has none.
+ const odd = "a\nb:1:1";
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = odd, .data = "needle\n" });
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "b", .data = "hay\n" });
+ const root = root_buf[0..try tmp.dir.realPath(testing.io, &root_buf)];
+ for ([_]Engine{ .walk, .rg }) |engine| {
+ const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ const pane = try p.setTestFile("x\n");
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ root, "main.txt" });
+ p.advance(1);
+ p.stream.engine = engine;
+ // No host workers: the search runs on the loop at the next tick.
+ panes.Query.open(p, 0, .grep, "", false);
+ const qp = for (p.panes) |slot| {
+ if (slot) |qp| if (qp.query != null) break qp;
+ } else return error.NoQueryPane;
+ const q = qp.query.?;
+ try query(p, qp.serial, .grep, "needle", root, .now);
+ p.update(.tick);
+ p.update(.tick);
+ if (engine == .rg and p.stream.used != .rg) return; // no rg here
+ try testing.expectEqual(@as(usize, 1), q.found.items.len);
+ const fd = q.found.items[0];
+ try testing.expectEqualStrings(odd, q.found_bytes.items[fd.path..][0..fd.path_len]);
+ try testing.expectEqual(@as(u32, 1), fd.line);
+ // The pane's rows: a line each, its name's newline written `\n`.
+ const f = &qp.file.?;
+ try testing.expectEqual(std.mem.count(u8, f.content, "\n"), f.location_rows.len);
+ try testing.expect(std.mem.indexOf(u8, f.content, "\"a\\nb:1:1\"") != null);
+ // Find: the same name, once, opening that file.
+ panes.Query.open(p, 0, .find, "", false);
+ p.update(.tick);
+ p.update(.tick);
+ const fq = for (p.panes) |slot| {
+ if (slot) |fp| if (fp.query) |got| if (got.source == .find) break got;
+ } else return error.NoFindPane;
+ try testing.expectEqual(@as(usize, 2), fq.names.cands.items.len);
+ }
+}
+
test "Stream: a big text's declarations are parsed on a worker, never the loop, and the rows of its / regroup under them" {
if (comptime !syntax.minimal_grammars) return error.SkipZigTest;
const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });