From 3785bc8b76d0437d6f2435f231e6441bb7668f46 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 20:39:23 -0800 Subject: [PATCH 1/2] Place: an empty password keeps a placed PDF linked with PDF Text at Outlines file.place reads an empty or null password as no password, but the app counted any password key as given. A PDF placed from a path with Link on and an empty password then took the PDF Text preference's Outlines and was embedded instead of linked. With Show Import Options off, an encrypted PDF placed with an empty password skipped the password prompt and went to file.place without a password. Both checks now read the password the way file.place does. --- crates/ui-egui/src/dialogs/import_pdf.rs | 18 +++++--- .../ui-egui/src/dialogs/tests_import_pdf.rs | 44 +++++++++++++++++++ docs/mcp.md | 4 +- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/dialogs/import_pdf.rs b/crates/ui-egui/src/dialogs/import_pdf.rs index b14cba49cd..c9ef6d6a67 100644 --- a/crates/ui-egui/src/dialogs/import_pdf.rs +++ b/crates/ui-egui/src/dialogs/import_pdf.rs @@ -189,12 +189,19 @@ pub fn offer_place(app: &mut VectorcraftApp, p: &Value) -> bool { offer(app, &name, &bytes, path, Some(p)) } +/// Whether the `file.place` params `p` give a password. `file.place` reads an empty or null +/// `password` as none; a value that isn't text counts as given, for `file.place` to refuse. +fn gives_password(p: &Value) -> bool { + p.get("password").is_some_and(|v| !v.is_null() && v.as_str() != Some("")) +} + /// [`offer_place`] when Show Import Options is off: asks (true) only for the password of an -/// encrypted PDF given no `password`, which nothing else opens, and places its first page (or -/// `page`) and crop box once it is unlocked; any other PDF is placed that way without asking. +/// encrypted PDF given no password (see [`gives_password`]), which nothing else opens, and places +/// its first page (or `page`) and crop box once it is unlocked; any other PDF is placed that way +/// without asking. pub fn offer_place_password(app: &mut VectorcraftApp, p: &Value) -> bool { // A `page` that isn't a page number is left for `file.place` to refuse. - if p.get("password").is_some() || p.get("page").is_some_and(|v| v.as_u64().is_none_or(|n| n == 0)) { + if gives_password(p) || p.get("page").is_some_and(|v| v.as_u64().is_none_or(|n| n == 0)) { return false; } let Some((name, bytes, path)) = place_source(app, p, |ext| matches!(ext, "pdf" | "ai" | "ait")) else { return false }; @@ -267,12 +274,13 @@ pub(crate) fn with_preferred_text_as(app: &VectorcraftApp, name: &str, bytes: &[ /// The `file.place` params `p` of a PDF the user places embedded (Link off, from bytes or with a /// password) get the `pdfTextAs` preference as their `textAs` when it is Outlines and they have no /// `textAs`. A linked page shows the file's own text, and a `.ai` or `.ait` file is placed as it -/// says. +/// says. An empty `password` is none, so a place from a path with Link on and an empty +/// `password` stays linked. pub(crate) fn place_with_preferred_text_as(app: &VectorcraftApp, p: &mut Value) { let given = |k: &str| p.get(k).is_some_and(|v| !v.is_null()); let path = p.get("path").and_then(Value::as_str); let name = path.or_else(|| p.get("name").and_then(Value::as_str)).unwrap_or_default(); - let linked = path.is_some() && p.get("link").and_then(Value::as_bool) != Some(false) && !given("password"); + let linked = path.is_some() && p.get("link").and_then(Value::as_bool) != Some(false) && !gives_password(p); if given("textAs") || linked || preferred_text_as(app) == TextAs::Text || fileio::extension(name) != "pdf" { return; } diff --git a/crates/ui-egui/src/dialogs/tests_import_pdf.rs b/crates/ui-egui/src/dialogs/tests_import_pdf.rs index 06bdf5e1b7..0f0cb30a1e 100644 --- a/crates/ui-egui/src/dialogs/tests_import_pdf.rs +++ b/crates/ui-egui/src/dialogs/tests_import_pdf.rs @@ -491,3 +491,47 @@ fn the_text_choice_applies_to_embedded_places_only() { assert!(!matches!(placed.kind, NodeKind::PlacedDocument(_)), "embedded: {:?}", placed.kind); assert_eq!(type_objects(&app), before, "placed as outlines"); } + +/// `file.place` reads an empty or null `password` as none: a place from a path with Link on stays +/// linked with the PDF Text preference at Outlines, and only a password that is given embeds it. +#[test] +fn an_empty_password_keeps_a_place_linked() { + let mut app = app(); + set_pdf_text(&mut app, "outlines"); + let dir = vectorcraft_testkit::TempDir::new("import-pdf-empty-password"); + let path = dir.join("one.pdf").to_string_lossy().into_owned(); + std::fs::write(&path, text_pages(1)).unwrap(); + for password in [json!(""), json!(null)] { + let mut p = json!({"path": path, "password": password}); + import_pdf::place_with_preferred_text_as(&app, &mut p); + assert_eq!(p, json!({"path": path, "password": password}), "no textAs with password {password}"); + } + let mut p = json!({"path": path, "password": "pw"}); + import_pdf::place_with_preferred_text_as(&app, &mut p); + assert_eq!(p["textAs"], "outlines", "a password embeds the page"); + + crate::place::run_for_user(&mut app, &json!({"path": path, "password": ""})).unwrap(); + opened(&mut app); + let st = app.session.active().unwrap(); + let placed = st.doc.node(st.selection.objects[0]).unwrap(); + assert!(matches!(placed.kind, NodeKind::PlacedDocument(_)), "linked: {:?}", placed.kind); +} + +/// With Show Import Options off, an encrypted PDF placed with an empty `password` asks for its +/// password, as one placed without `password` does; a password that is given goes to `file.place`. +#[test] +fn an_empty_password_still_asks_for_the_password() { + let mut app = app(); + let bytes = pdf(&[PdfPage::new(120.0, 60.0, "1 0 0 rg 0 0 20 20 re f")], Some("pw")); + let data = vectorcraft_format::base64_encode(&bytes); + for password in [json!(""), json!(null)] { + app.ui.dialog = None; + let p = json!({"name": "locked.pdf", "dataBase64": data, "password": password}); + assert!(import_pdf::offer_place_password(&mut app, &p), "asks with password {password}"); + assert_eq!((field(&app, "__locked"), field(&app, "__passwordOnly")), (json!(true), json!(true))); + } + app.ui.dialog = None; + let p = json!({"name": "locked.pdf", "dataBase64": data, "password": "pw"}); + assert!(!import_pdf::offer_place_password(&mut app, &p), "a given password is placed with"); + assert!(app.ui.dialog.is_none()); +} diff --git a/docs/mcp.md b/docs/mcp.md index 3cb8d1d239..49e9b808d1 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -8982,7 +8982,7 @@ unless `link: false`; a Photoshop document as its merged image), an SVG as one g and swatches it uses. A VectorCraft document read from `path` is a placed document: one locked object showing its artboard `page` (or, with `crop: "bounding"`, its art's bounds), linked to the file and read again when it changes (see Linked images), and vectors in every output; with `link: false` (or from `dataBase64`) it is an editable copy -of its art, as one clipped group. A PDF, `.ai` or `.ait` page read from `path` (with neither `password` nor +of its art, as one clipped group. A PDF, `.ai` or `.ait` page read from `path` (with neither a non-empty `password` nor `textAs: "outlines"`) is a placed document the same way, showing page `page` clipped to its `crop` box (or its art's bounds); with `link: false` it is placed as one clipped group. An EPS file, a PostScript file or a PostScript `.ai` read from `path` is a placed document too, showing the art `link: false` places (clipped to its bounding box, or its art's bounds with `crop: "bounding"`); @@ -9055,7 +9055,7 @@ slices (Place PSD). `showImportOptions: false` places such a file without asking its dialog: the text options, the DXF fit, lineweight, centering and layer choices with the drawing at 1:1 in its own unit, and the PSD conversion, hidden-layer and Import Slices choices. A PDF is placed on page 1 (or `page`) and its crop box, and an encrypted PDF given no -`password` still asks for the password. An encrypted PDF given a `page` and no `password` asks for the password with +`password` (or an empty one) still asks for the password. An encrypted PDF given a `page` and no `password` asks for the password with Show Import Options on too, and places that page. A `showImportOptions` that is not true or false is refused, and nothing is placed. The Place dialog (File › Place, or `file.place {paths}`) has a Show Import Options checkbox after Link, Template and Replace ([Place multiple files in a document](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-other-file-types/place-multiple-files-in-a-document.html)). From 24be579cc47f57abdff8bf53666f28d79300ac57 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 18:57:45 -0800 Subject: [PATCH 2/2] Tests: the empty-password Place tests use the dialog host The Import PDF dialog now lives in the craft dialog host, so an_empty_password_still_asks_for_the_password closes each dialog with cancel_by_id and checks it with the file's dialog_id helper instead of app.ui.dialog. --- crates/ui-egui/src/dialogs/tests_import_pdf.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs/tests_import_pdf.rs b/crates/ui-egui/src/dialogs/tests_import_pdf.rs index 5051b8338b..30a1aa9d65 100644 --- a/crates/ui-egui/src/dialogs/tests_import_pdf.rs +++ b/crates/ui-egui/src/dialogs/tests_import_pdf.rs @@ -525,14 +525,18 @@ fn an_empty_password_still_asks_for_the_password() { let mut app = app(); let bytes = pdf(&[PdfPage::new(120.0, 60.0, "1 0 0 rg 0 0 20 20 re f")], Some("pw")); let data = vectorcraft_format::base64_encode(&bytes); + let close = |app: &VectorcraftApp| { + let id = dialog_id(app).expect("an Import PDF dialog"); + assert!(app.dialogs().unwrap().with(|host| host.cancel_by_id(&ctx(app), id))); + assert!(!is_open(app)); + }; for password in [json!(""), json!(null)] { - app.ui.dialog = None; let p = json!({"name": "locked.pdf", "dataBase64": data, "password": password}); assert!(import_pdf::offer_place_password(&mut app, &p), "asks with password {password}"); assert_eq!((field(&app, "__locked"), field(&app, "__passwordOnly")), (json!(true), json!(true))); + close(&app); } - app.ui.dialog = None; let p = json!({"name": "locked.pdf", "dataBase64": data, "password": "pw"}); assert!(!import_pdf::offer_place_password(&mut app, &p), "a given password is placed with"); - assert!(app.ui.dialog.is_none()); + assert!(!is_open(&app)); }