From 519ffd4987ad30f702b824ab7a3ca6842c062254 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 3 Nov 2026 23:01:19 -0500 Subject: [PATCH] fix(format): import a Sketch page once however often the file lists it (#1973) --- crates/format/src/sketch.rs | 5 +++++ crates/format/src/sketch/tests.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/crates/format/src/sketch.rs b/crates/format/src/sketch.rs index 8186ce26d..01b68e6c9 100644 --- a/crates/format/src/sketch.rs +++ b/crates/format/src/sketch.rs @@ -226,11 +226,16 @@ impl<'b> Archive<'b> { }; let refs = document.get("pages").and_then(Value::as_array).map(Vec::as_slice).unwrap_or_default(); let mut pages = Vec::new(); + let mut seen = std::collections::HashSet::new(); for r in refs.iter().take(MAX_PAGES) { let Some(id) = r.get("_ref").and_then(Value::as_str).and_then(|s| s.strip_prefix("pages/")).filter(|id| valid_id(id)) else { warnings.push("pages the document lists without a valid reference were skipped".into()); continue; }; + // A page listed twice is read once: a repeated reference must not repeat the unpacking. + if !seen.insert(id) { + continue; + } match json_member(&mut z, &format!("pages/{id}.json"), max_member, &mut total) { Ok(page) if page.is_object() => pages.push((id.to_string(), page)), Ok(_) => warnings.push("pages that aren't JSON objects were skipped".into()), diff --git a/crates/format/src/sketch/tests.rs b/crates/format/src/sketch/tests.rs index b4368de12..d8ace8be9 100644 --- a/crates/format/src/sketch/tests.rs +++ b/crates/format/src/sketch/tests.rs @@ -35,6 +35,13 @@ fn pages_become_pages_in_document_order() { assert_eq!(page_names(&doc), ["Beta", "Alpha"]); } +#[test] +fn a_page_listed_twice_is_imported_once() { + let z = sketch_zip("50.2", 103, document(&["A", "A", "A"]), &[page("A", "Alpha", vec![])], &[]); + let (doc, _) = import(&z, "f").unwrap(); + assert_eq!(page_names(&doc), ["Alpha"]); +} + #[test] fn older_than_48_is_refused() { let z = sketch_zip("47.1", 95, document(&["P"]), &[page("P", "P", vec![])], &[]);