mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 14:06:09 +00:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user