Cell: cell.set without an input is an error

cell.set treated a missing input as an empty string, so a call that forgot the
input (or sent it under the wrong key) cleared the cell and reported success.
It now returns an error when neither `input` nor `value` is given. An explicit
empty string still clears the cell.
This commit is contained in:
Mikkel Georgsen 2026-10-10 18:39:57 +02:00
parent 90b3c41eec
commit f69861f7e3
2 changed files with 17 additions and 2 deletions

View File

@ -196,8 +196,11 @@ fn cell_set(s: &mut Session, p: &Json) -> Result<Json> {
Some(c) => c,
None => s.doc()?.selection.active,
};
let input =
str_param(p, "input").or_else(|| str_param(p, "value")).map(str::to_string).or_else(|| p.get("value").map(json_to_input)).unwrap_or_default();
let input = str_param(p, "input")
.or_else(|| str_param(p, "value"))
.map(str::to_string)
.or_else(|| p.get("value").map(json_to_input))
.ok_or_else(|| bad("cell.set", "missing `input` (or `value`)"))?;
let array = bool_param(p, "array").unwrap_or(false);
let protected =
s.doc()?.wb.sheet(sheet).is_some_and(|sh| sh.is_protected() && s.doc().is_ok_and(|d| d.wb.styles.get(sh.style_id(at)).protection.locked));

View File

@ -339,6 +339,18 @@ fn serve_loop_over_buffers() {
assert!(lines[2]["result"]["content"][0]["text"].as_str().unwrap().contains("42"));
}
#[test]
fn cell_set_without_input_is_error() {
let mut s = server();
ok(&mut s, "set_cell", json!({"cell": "B2", "input": "keep"}));
fails(&mut s, "execute_command", json!({"command": "cell.set", "params": {"cell": "B2"}}));
fails(&mut s, "execute_command", json!({"command": "cell.set", "params": {}}));
assert_eq!(ok(&mut s, "get_cell", json!({"cell": "B2"}))["text"], "keep");
// An explicit empty string still clears.
ok(&mut s, "execute_command", json!({"command": "cell.set", "params": {"cell": "B2", "input": ""}}));
assert_eq!(ok(&mut s, "get_cell", json!({"cell": "B2"}))["text"], "");
}
#[test]
fn remote_backend_over_tcp() {
// A fake app: answers engine.execute by running a headless session; closes after the first