M11: doc_optimize refuses an unknown key in mono

A misspelled key ({"mono": {"compresson": "retain"}}) left the preset's
setting in place unnoticed; it is now InvalidArgs (from CodeRabbit's
review).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BfMGHQNgdq5yf5tKZHGR3z
This commit is contained in:
Grzegorz MartensandClaude Opus 5.5 committed 2026-10-29 20:47:39 +01:00
1 parent 0a5f8bce2d
commit faa582e7f7
2 files changed
+7 -3

No files matched your search

+4
View File
@@ -320,6 +320,10 @@ impl Automation {
if let Some(mono) = a.get("mono") {
let unknown = |c: &Value| ToolError::InvalidArgs(format!("unknown mono compression {c} (ccitt_g4, retain)"));
let mono = mono.as_object().ok_or_else(|| ToolError::InvalidArgs("mono must be an object: { compression: ccitt_g4|retain }".into()))?;
// A misspelled key would otherwise leave the preset's setting in place unnoticed.
if let Some(key) = mono.keys().find(|k| *k != "compression") {
return Err(ToolError::InvalidArgs(format!("unknown mono key {key:?} (compression)")));
}
if let Some(c) = mono.get("compression") {
settings.mono = match c.as_str() {
Some("ccitt_g4" | "ccitt" | "g4") => MonoCompression::CcittG4,
+3 -3
View File
@@ -6455,9 +6455,9 @@ fn doc_optimize_stores_black_and_white_images_as_ccitt_group_4() {
})
.collect();
assert_eq!(filters, [b"CCITTFaxDecode".to_vec()]);
// An unknown compression, one that isn't a name, or a mono that isn't an object is refused,
// not read as the default.
for mono in [json!({ "compression": "jbig2" }), json!({ "compression": false }), json!("retain")] {
// An unknown compression, one that isn't a name, a misspelled key, or a mono that isn't an
// object is refused, not read as the default.
for mono in [json!({ "compression": "jbig2" }), json!({ "compression": false }), json!({ "compresson": "retain" }), json!("retain")] {
assert!(matches!(a.call("doc_optimize", &json!({ "doc": doc, "path": "x.pdf", "mono": mono })), Err(ToolError::InvalidArgs(_))), "{mono}");
}
}