diff --git a/crates/engine/src/cmd/tags.rs b/crates/engine/src/cmd/tags.rs index 8707e7dc1e..2c5fbbeceb 100644 --- a/crates/engine/src/cmd/tags.rs +++ b/crates/engine/src/cmd/tags.rs @@ -78,8 +78,12 @@ fn tag_index(d: &Document, id: NodeId, p: &Value, c: &str) -> Result { tags_of(n).iter().position(|t| t.id == tag).ok_or_else(|| bad(c, format!("object {} has no tag {tag}", id.0))) } -/// The text `p` gives for `key` (a tag's name or value), at most [`MAX_TAG_TEXT`] bytes. +/// The text `p` gives for `key` (a tag's name or value), at most [`MAX_TAG_TEXT`] bytes. `None` +/// when `p` leaves it out; a null is an error. fn tag_text<'a>(p: &'a Value, key: &str, c: &str) -> Result> { + if p.get(key).is_some_and(Value::is_null) { + return Err(bad(c, format!("`{key}` must be a string"))); + } let t = text_param(p, key, c)?; if t.is_some_and(|t| t.len() > MAX_TAG_TEXT) { return Err(bad(c, format!("a tag's {key} is longer than 65,536 bytes"))); diff --git a/crates/engine/src/tests/script_tags.rs b/crates/engine/src/tests/script_tags.rs index d84f8d8b40..79acc49546 100644 --- a/crates/engine/src/tests/script_tags.rs +++ b/crates/engine/src/tests/script_tags.rs @@ -167,6 +167,10 @@ fn a_tag_goes_stale_when_it_or_its_item_is_deleted() { // A tag added after another was deleted does not take the deleted one's place. let e = failure(&mut s, "var all = app.activeDocument.pageItems[0].tags, t = all[0]; t.remove(); all.add(); t.name;"); assert!(e.contains("Stale tag"), "{e}"); + // Nor after the run undoes the add: the undone document's next id does not give the tag's id + // out again. + let e = failure(&mut s, "var all = app.activeDocument.pageItems[0].tags, t = all.add(); vc.run('edit.undo'); all.add().name = 'u'; t.name;"); + assert!(e.contains("Stale tag"), "{e}"); // Nor when the deleted tag's id was ahead of the document's next id (a tag pasted from // another document). let d = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc); @@ -188,6 +192,9 @@ fn tag_commands_check_their_params_and_skip_unchanged_edits() { for (id, p) in [ ("object.tag.add", json!({"id": a.0, "name": too_long})), ("object.tag.add", json!({"id": a.0, "value": 3})), + ("object.tag.add", json!({"id": a.0, "name": null})), + ("object.tag.set", json!({"id": a.0, "tag": tag, "name": null, "value": "updated"})), + ("object.tag.set", json!({"id": a.0, "tag": tag, "value": null})), ("object.tag.add", json!({"id": 999_999})), ("object.tag.add", json!({"id": "1"})), ("object.tag.set", json!({"id": a.0, "tag": tag})), diff --git a/docs/mcp.md b/docs/mcp.md index b5dedf2874..8b93898c75 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -6824,7 +6824,7 @@ order → `{tags: [{tag, name, value}]}`, where `tag` tells each one apart from changes its name or value → `{changed}`, `object.tag.remove {id, tag}` deletes it, and `object.tag.removeAll {ids?}` deletes every tag of the objects in `ids` or the selection → `{changed: objects}`; each edit is one undo step, and an edit that changes nothing adds none. Names may be empty or repeated. An object has at most 64 tags, each name and -value at most 65,536 bytes; a layer or a ruler guide has none, and a bad value is an error that changes nothing, as is +value at most 65,536 bytes; a layer or a ruler guide has none, and a bad value (a null name or value included) is an error that changes nothing, as is an add in a document whose ids have reached the top of their range (a damaged or hand-made file). The native file keeps the tags and their `tag` ids, and opening one keeps the first 64 tags of each object whose name and value are within the limit, giving a new id to a tag whose id is missing, out of range or repeated. Copies keep their source's tags. Other file formats do not write them.