From fcc8f717dc85c3f32799d9e15b5c6d0fbbbeef88 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 18:15:21 -0800 Subject: [PATCH] Scripts: test that a group's pathItems.removeAll() refuses an id found outside it Adds a test that builds a document where a path outside a group has the same id as a path in the group, and checks that the group's pathItems.removeAll() throws and deletes nothing. --- crates/engine/src/tests/script_dom.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/engine/src/tests/script_dom.rs b/crates/engine/src/tests/script_dom.rs index 6b45c5105f..1bab9b1e4b 100644 --- a/crates/engine/src/tests/script_dom.rs +++ b/crates/engine/src/tests/script_dom.rs @@ -4080,6 +4080,33 @@ fn group_path_items_remove_all_walks_only_the_group() { assert!(visits <= 3, "{visits} objects walked to empty a group of two paths"); } +/// In a damaged document where a path outside a group has the same id as a path in it, the +/// group's `pathItems.removeAll()` throws and deletes nothing, instead of deleting the outside path. +#[test] +fn group_path_items_remove_all_refuses_an_id_found_outside_the_group() { + let (mut s, a, b) = doc(); + s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + s.execute("object.group", &json!({})).unwrap(); + let c = rect(&mut s, 200.0, 200.0, 20.0, 20.0); + s.execute("select.set", &json!({"ids": [c.0]})).unwrap(); + s.execute("object.arrange.sendToBack", &json!({})).unwrap(); + s.execute("select.none", &json!({})).unwrap(); + let d = std::sync::Arc::make_mut(&mut s.active_mut().unwrap().doc); + d.node_mut(c).unwrap().id = a; + d.drop_lookup_cache(); + // The first object in tree order with the id is the one outside the group. + assert_eq!(d.index_path(a).map(|p| p.len()), Some(2)); + let n = d.layers[0].children().map_or(0, Vec::len); + let out = log( + &mut s, + "var d = app.activeDocument, m = ''; try { d.groupItems[0].pathItems.removeAll(); } catch (e) { m = e.message; }\ + vc.log(m); vc.log(d.groupItems[0].pathItems.length);", + ); + assert_eq!(out, vec![json!(format!("cannot delete PathItem {}: its id also names another object", a.0)), json!(2)]); + let d = &s.active().unwrap().doc; + assert_eq!(d.layers[0].children().map_or(0, Vec::len), n, "the path outside the group is kept"); +} + /// The document's `pathItems.removeAll()` refuses to delete the path that clips a group while the /// group keeps other art, and deletes nothing, as the scoped collections do. #[test]