mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-07 11:03:15 +00:00
fix(format): import a Sketch page once however often the file lists it (#1973)
This commit is contained in:
1 parent
5f022aa8a9
commit
519ffd4987
2 files changed
+12
No files matched your search
@@ -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()),
|
||||
|
||||
@@ -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![])], &[]);
|
||||
|
||||
Reference in new issue
Block a user