mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-06 14:04:01 -05:00
Deduplicate the media option in spool jobs
A duplicated media option can make the spooler or a virtual printer such as Microsoft Print to PDF reject or crash on the job instead of feeding the laid-out paper. Remove any existing media entry from the user options before appending the laid-out paper's media option, so the job carries exactly one media value. Test: spool_job_does_not_duplicate_media_option failed before the change and passes after.
This commit is contained in:
1 parent
c944f106dd
commit
2ec44a88ac
1 file changed
+16
-1
@@ -143,7 +143,10 @@ fn spool_job(
|
||||
grey_pages: false,
|
||||
title,
|
||||
options: {
|
||||
let mut options: Vec<(String, String)> = options.into_iter().chain(media.map(|m| ("media".to_string(), m.to_string()))).collect();
|
||||
let mut options: Vec<(String, String)> = options.into_iter().filter(|(k, _)| k != "media").collect();
|
||||
if let Some(m) = media {
|
||||
options.push(("media".to_string(), m.to_string()));
|
||||
}
|
||||
print::add_cups_orientation(&mut options, sheets);
|
||||
options
|
||||
},
|
||||
@@ -581,4 +584,16 @@ mod tests {
|
||||
assert_eq!(paper_size(spec), None, "{spec}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A user-supplied `media` option must not reach the spooler alongside the
|
||||
/// laid-out paper's own `media` option: the job carries exactly one `media`
|
||||
/// entry, and it is the paper the sheets were laid out on.
|
||||
#[test]
|
||||
fn spool_job_does_not_duplicate_media_option() {
|
||||
let (index, _) = paper_named(None).unwrap();
|
||||
let job = spool_job(&Args(&json!({ "options": { "InputSlot": "Tray3", "media": "A4" } })), "Office", "a.pdf".into(), None, index).unwrap();
|
||||
let media: Vec<&(String, String)> = job.options.iter().filter(|(k, _)| k == "media").collect();
|
||||
assert_eq!(media, [print::media_option(index).as_ref().unwrap()]);
|
||||
assert!(job.options.contains(&("InputSlot".to_string(), "Tray3".to_string())));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user