summaryrefslogtreecommitdiff
path: root/src/ninep/ctl.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/ctl.zig')
-rw-r--r--src/ninep/ctl.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index fa6310bb..1bf916a9 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -991,6 +991,10 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
if (apply) _ = p.answerQuestion(id, if (choice[0] == '-') null else choice[0]);
} else if (!apply) {
if (checkBuiltin(p, req, line, .pane)) |refusal| return refusal;
+ // Edit on a pane with no text is the refusal a data write
+ // there gets, EINVAL, before anything runs.
+ if (std.mem.startsWith(u8, line, "Edit") and pane_files.fileOf(p.panes[p.paneBySerial(serial).?].?) == null)
+ return tree.failText(req.tag, E.INVAL, pane_files.e_no_text);
} else if (runBuiltin(p, req, p.paneBySerial(serial).?, line)) |refusal| {
return refusal;
}
@@ -4133,3 +4137,15 @@ test "a Rename that reaches other files previews them, says so, and is the pane
try testing.expectEqual(preview.serial, p.fs.lsp_result.?);
try testing.expect(th.logHas(p, "Rename: 2 edit(s) across files, previewed, not applied"));
}
+
+test "Edit on an image pane is refused as a data write there is, EINVAL, before it runs" {
+ const p = try withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ const doc = try p.newDocPane(p.freeSlot().?);
+ doc.image = .{ .path = try p.gpa.dupe(u8, "/tmp/pardes-pic.ppm") };
+ const edit = wr(p, Node.of(doc.serial, .ctl), "Edit ,d\n");
+ const data = wr(p, Node.of(doc.serial, .data), "x");
+ try testing.expectEqual(E.INVAL, edit.errno());
+ try testing.expectEqualStrings(data.reply.ename, edit.reply.ename);
+ try testing.expectEqual(E.INVAL, wr(p, Node.of(doc.serial, .name), "/tmp/other.ppm\n").errno());
+}