From 27ce6f7584b3c869a0671b83d7cde4269a595e74 Mon Sep 17 00:00:00 2001 From: umesh429 Date: Mon, 12 Oct 2026 11:25:06 +0100 Subject: [PATCH] CLI: audit rejects unknown options before reading the file (fixes #1332) (#1372) `pdfcraft-cli audit` skipped option validation, so a misspelled `--passwrod` fell through to a file-read error instead of naming the bad option. Audit now runs `validate_options` first, like `info`, and the options test covers it. Co-authored-by: umesh429 <3474974+umesh429@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- apps/pdfcraft-cli/src/main.rs | 2 ++ apps/pdfcraft-cli/tests/options.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/apps/pdfcraft-cli/src/main.rs b/apps/pdfcraft-cli/src/main.rs index 351cc67c..052e7be3 100644 --- a/apps/pdfcraft-cli/src/main.rs +++ b/apps/pdfcraft-cli/src/main.rs @@ -151,6 +151,7 @@ fn version() -> Result<(), CliError> { /// Audit a document for faux redactions. Prints the findings as JSON; fails when any are /// found so scripts and CI can gate on it, and when the audit itself cannot run. fn audit(args: &[String]) -> Result<(), CliError> { + validate_options("audit", args, AUDIT_OPTIONS)?; let path = *positional(args).first().ok_or("audit: missing file")?; let bytes = read(path)?; let doc = pdfcraft_cos::Document::open_with_password(bytes, flag(args, "--password")).map_err(|e| format!("{path}: {e}"))?; @@ -213,6 +214,7 @@ fn validate_options(command: &str, args: &[String], specs: &[OptionSpec]) -> Res } const INFO_OPTIONS: &[OptionSpec] = &[OptionSpec { name: "--password", takes_value: true }]; +const AUDIT_OPTIONS: &[OptionSpec] = &[OptionSpec { name: "--password", takes_value: true }]; const TEXT_OPTIONS: &[OptionSpec] = &[OptionSpec { name: "--page", takes_value: true }, OptionSpec { name: "--password", takes_value: true }]; const COMBINE_OPTIONS: &[OptionSpec] = &[OptionSpec { name: "--out", takes_value: true }]; const EXTRACT_OPTIONS: &[OptionSpec] = &[ diff --git a/apps/pdfcraft-cli/tests/options.rs b/apps/pdfcraft-cli/tests/options.rs index c337d27e..9576d59a 100644 --- a/apps/pdfcraft-cli/tests/options.rs +++ b/apps/pdfcraft-cli/tests/options.rs @@ -15,6 +15,8 @@ fn non_edit_commands_reject_unknown_options_before_io() { vec!["render", "missing.pdf", "--dppi", "96", "--out", "out.png"], vec!["check-one", "missing.pdf", "--edti"], vec!["check", "missing.pdf", "--timout", "2"], + vec!["audit", "missing.pdf", "--passwrod", "x"], + vec!["audit", "missing.pdf", "--nonsense", "1"], vec!["run", "doc_open", "--roto", "/tmp"], vec!["ui", "--contro", "control.json", "state"], ] {