From a9a1aa36a2a5b11b891fb861e16ba4e4d5a1e3ee Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:26:14 +0100 Subject: [PATCH 1/4] M14: preserve existing PDF suffixes in web exports Recognize an existing PDF extension without changing its case or the requested filename. --- crates/ui-egui/src/app/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index 86bed7fe6d..75d6ca817e 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -145,7 +145,7 @@ impl WordApp { // Web: saving and exporting become downloads. if self.services.download.is_some() && matches!(id, "file.save" | "file.saveAs" | "file.exportPdf" | "file.exportPng") { let name = params.get("path").and_then(Value::as_str).map(str::to_string).unwrap_or_else(|| self.web_save_name(id)); - let name = if id == "file.exportPdf" && !name.ends_with(".pdf") { format!("{name}.pdf") } else { name }; + let name = if id == "file.exportPdf" && !name.to_ascii_lowercase().ends_with(".pdf") { format!("{name}.pdf") } else { name }; // A save with a password encrypts this and later saves (`file.save`'s `password`). if matches!(id, "file.save" | "file.saveAs") && let Some(pw) = params.get("password").filter(|v| !v.is_null()) From 3e776e4c7d6fb901d2439738b9ced1513ec2c426 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:27:16 +0100 Subject: [PATCH 2/4] M14: cover PDF suffix case in web downloads Assert exact delivered filenames and PDF bytes for lowercase, uppercase, mixed-case Unicode and missing suffixes. --- crates/ui-egui/src/file_dialogs/tests.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/ui-egui/src/file_dialogs/tests.rs b/crates/ui-egui/src/file_dialogs/tests.rs index 6ab3e77552..4d022b312a 100644 --- a/crates/ui-egui/src/file_dialogs/tests.rs +++ b/crates/ui-egui/src/file_dialogs/tests.rs @@ -465,6 +465,26 @@ fn export_pdf_without_a_path_asks_where_to_save() { let _ = std::fs::remove_dir_all(&dir); } +/// An explicit web PDF export keeps an existing PDF suffix regardless of ASCII case. +#[test] +fn web_pdf_export_keeps_an_existing_suffix_in_any_case() { + let downloaded = Rc::new(RefCell::new(Vec::new())); + let captured = downloaded.clone(); + let services = Services { + download: Some(Box::new(move |name, bytes| { + captured.borrow_mut().push((name.to_string(), bytes.starts_with(b"%PDF"))); + Ok(()) + })), + ..Default::default() + }; + let mut a = WordApp::new(Session::new(wordcraft_doc::Document::new()), services); + for (name, expected) in [("Report.pdf", "Report.pdf"), ("Report.PDF", "Report.PDF"), ("Résumé.PdF", "Résumé.PdF"), ("Report", "Report.pdf")] { + let result = a.execute("file.exportPdf", json!({"path": name})).unwrap(); + assert_eq!(result["downloaded"], expected, "{name}"); + assert_eq!(downloaded.borrow().last().cloned(), Some((expected.to_string(), true)), "{name}"); + } +} + /// Open, Save As and Export PNG from the command search (no path) ask for a file the same way. #[test] fn file_commands_without_a_path_ask_for_one() { From b354e0f870655f085f39a445d6051517b8e50ebb Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:53:49 +0100 Subject: [PATCH 3/4] M14: bound PDF suffix checks to four bytes --- crates/ui-egui/src/app/commands.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index 75d6ca817e..9c5775806d 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -145,7 +145,9 @@ impl WordApp { // Web: saving and exporting become downloads. if self.services.download.is_some() && matches!(id, "file.save" | "file.saveAs" | "file.exportPdf" | "file.exportPng") { let name = params.get("path").and_then(Value::as_str).map(str::to_string).unwrap_or_else(|| self.web_save_name(id)); - let name = if id == "file.exportPdf" && !name.to_ascii_lowercase().ends_with(".pdf") { format!("{name}.pdf") } else { name }; + // Inspect only the suffix bytes: no full-name allocation or UTF-8 slicing. + let has_pdf_suffix = name.as_bytes().last_chunk::<4>().is_some_and(|suffix| suffix.eq_ignore_ascii_case(b".pdf")); + let name = if id == "file.exportPdf" && !has_pdf_suffix { format!("{name}.pdf") } else { name }; // A save with a password encrypts this and later saves (`file.save`'s `password`). if matches!(id, "file.save" | "file.saveAs") && let Some(pw) = params.get("password").filter(|v| !v.is_null()) From 5f228a0e24a30bf7dac17ee43cfa35eb0a0209df Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:54:24 +0100 Subject: [PATCH 4/4] M14: cover Unicode and misleading PDF filename suffixes Added additional test cases for PDF file name handling in file dialogs. --- crates/ui-egui/src/file_dialogs/tests.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/file_dialogs/tests.rs b/crates/ui-egui/src/file_dialogs/tests.rs index 4d022b312a..000aca1108 100644 --- a/crates/ui-egui/src/file_dialogs/tests.rs +++ b/crates/ui-egui/src/file_dialogs/tests.rs @@ -478,7 +478,20 @@ fn web_pdf_export_keeps_an_existing_suffix_in_any_case() { ..Default::default() }; let mut a = WordApp::new(Session::new(wordcraft_doc::Document::new()), services); - for (name, expected) in [("Report.pdf", "Report.pdf"), ("Report.PDF", "Report.PDF"), ("Résumé.PdF", "Résumé.PdF"), ("Report", "Report.pdf")] { + for (name, expected) in [ + ("Report.pdf", "Report.pdf"), + ("Report.PDF", "Report.PDF"), + ("Résumé.PdF", "Résumé.PdF"), + ("😀.PDF", "😀.PDF"), + (".hidden.PDF", ".hidden.PDF"), + ("Report..PDF", "Report..PDF"), + ("é", "é.pdf"), + ("😀", "😀.pdf"), + ("Report.pdf.exe", "Report.pdf.exe.pdf"), + ("Report.PDF", "Report.PDF.pdf"), + ("Report.pdf.", "Report.pdf..pdf"), + ("Report", "Report.pdf"), + ] { let result = a.execute("file.exportPdf", json!({"path": name})).unwrap(); assert_eq!(result["downloaded"], expected, "{name}"); assert_eq!(downloaded.borrow().last().cloned(), Some((expected.to_string(), true)), "{name}");