summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ninep/ctl.zig15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index e44368ea..0bbc0319 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -910,8 +910,10 @@ fn acmeCtl(p: *Pardes, req: Req, serial: u32, line: []const u8, apply: bool) Acm
const File = tree.PaneFile;
// A word written to one of the pane's own files, as acme's is to its.
const Into = struct { file: File, data: []const u8 };
+ // `name` takes all after its one blank, as the name file takes what is
+ // written: a blank at its start is refused there, not trimmed here.
const into: ?Into = if (std.mem.eql(u8, word, "name") and rest.len > 0)
- .{ .file = .name, .data = rest }
+ .{ .file = .name, .data = line[word.len + 1 ..] }
else if (std.mem.eql(u8, line, "clean"))
.{ .file = .dirty, .data = "0" }
else if (std.mem.eql(u8, line, "dirty"))
@@ -2443,6 +2445,17 @@ test "a look that misses file:/re/ names the file, and is logged as its pane's"
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "err {d} look: {s}/f.txt: no match for regexp", .{ f_serial, dir })));
}
+test "the ctl word name refuses a leading blank, as the name file does" {
+ const p = try withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ const serial = serialOf(p);
+ const r = wr(p, Node.of(serial, .ctl), "name /tmp/lead.txt\n");
+ try testing.expectEqual(E.INVAL, r.errno());
+ try testing.expectEqualStrings("bad character in file name: a blank at its start", r.reply.ename);
+ try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "name /tmp/ok.txt\n").reply.status);
+ try testing.expectEqualStrings("/tmp/ok.txt", pane_files.nameOf(p, p.panes[0].?));
+}
+
test "a builtin that takes no argument, written with one to an exec, is refused wrong #args, as at a ctl" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();