From 7451b07a96ac3d06d32c33c807a56f609c0a70c8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 16:19:42 -0800 Subject: [PATCH] Save PDF: the saved Summary writes line breaks inside option values as LF A text option such as the output condition could carry CRLF or CR into the file, which then mixed line endings. --- crates/ui-egui/src/dialogs/save_pdf.rs | 5 +++-- crates/ui-egui/src/dialogs/save_pdf/tests.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index f60236c3bf..8f16594f1d 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -1084,7 +1084,8 @@ fn unchanged_line(d: &Dialog) -> String { /// The Summary of `document.pdfSettings`'s reply `v` as text, line for line as the section shows /// it in the interface language: Options and each changed option (or the line saying none -/// changed), a blank line, then Warnings and each warning (or "None."). Lines end in LF. +/// changed), a blank line, then Warnings and each warning (or "None."). Lines end in LF, including +/// line breaks inside an option's value. fn summary_text(d: &Dialog, v: &Value) -> String { let lang = crate::i18n::current(); let mut lines = vec![tl!("Options").to_string()]; @@ -1100,7 +1101,7 @@ fn summary_text(d: &Dialog, v: &Value) -> String { lines.push(tl!("None.").to_string()); } lines.extend(warnings.iter().map(|w| warning_line(lang, w.as_str().unwrap_or_default()))); - let mut text = lines.join("\n"); + let mut text = lines.join("\n").replace("\r\n", "\n").replace('\r', "\n"); text.push('\n'); text } diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index 20a5522157..b4fa08fb01 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -94,6 +94,19 @@ fn save_summary_writes_the_summary_as_text() { assert_eq!(app.ui.status, "Saved /tmp/Ünïcode (1) summary.txt"); } +/// A text option whose value holds CRLF or CR line breaks is written with LF line breaks, so the +/// file has one kind of line ending. +#[test] +fn save_summary_writes_line_breaks_in_values_as_lf() { + let (mut app, written, _) = app(); + app.run("file.export.pdf", json!({})).unwrap(); + set_field(&mut app, "output.outputCondition", json!("first\r\nsecond\rthird")); + app.run(SAVE_SUMMARY, json!({"path": "/tmp/summary.txt"})).unwrap(); + let text = String::from_utf8(written.borrow()[0].1.clone()).unwrap(); + assert!(!text.contains('\r'), "LF line endings: {text:?}"); + assert!(text.contains("first\nsecond\nthird\n"), "{text:?}"); +} + /// With every option as the preset has it and nothing to warn about, the file holds the lines /// that say so, in the interface language. #[test]