Skip to content

fix(pdf): reject invalid slide selector types before export - #2302

Open
MMexicann wants to merge 1 commit into
storytold:mainfrom
MMexicann:patch-33
Open

MMexicann wants to merge 1 commit into
storytold:mainfrom
MMexicann:patch-33

Conversation

@MMexicann

@MMexicann MMexicann commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

DeckCraft’s PDF export rejects malformed slides values before writing the destination.

A number, boolean, or object was treated as an omitted selector. A caller could therefore export every visible slide and overwrite the destination by mistake. The PDF option parser now accepts the existing list and range forms and reports unsupported types. Omitted, null, and blank range values keep their previous meaning.

invalid_pdf_slide_selector_keeps_the_existing_destination exercises file.export against a seeded file and checks the error and original bytes. Eight isolated Rust checks passed using the PDF option parser and real serde_json; the original code accepted all three invalid types. The full DeckCraft engine suite, file-writing regression, and Clippy were not run locally.

Summary by CodeRabbit

  • Bug Fixes
    • Invalid PDF slide selector values now return a bad-parameters error instead of silently disabling slide filtering.
    • Export errors leave an existing destination file unchanged.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

PDF export now treats null and string slide selectors as unfiltered. It rejects unsupported selector values with a file.export bad-parameters error. A test checks that a numeric selector leaves existing destination bytes unchanged.

Changes: PDF export

Layer / File(s) Summary
Validate PDF slide selectors
crates/engine/src/cmd/file.rs
pdf_options accepts null and string selectors without filtering, and rejects other unsupported values with a file.export bad-parameters error. A test verifies the error for a numeric selector and checks that the destination’s existing bytes remain unchanged.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: echelon, silvertree2010, dylanmtaylor

Merge Risk: Minimal · up to 7b988

PDF export now rejects unsupported slide selector values before touching the destination file, so a bad option no longer overwrites existing output. The change is narrow, tested, and carries no identified merge risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: invalid slide selector types for PDF export are now rejected before the export runs. The raw summary confirms that pdf_options now returns a bad-parameters error for n…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: invalid slide selector types for PDF export are now rejected before the export runs. The raw summary confirms that pdf_options now returns a bad-parameters error for non-string, non-array slide values, and the PR objectives describe the same intent. The title is specific and matches the changeset, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.1)

Clippy execution timed out
Clippy (1.99.1) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0ccc68f and 7b98875.

Files selected for processing: 1

  • crates/engine/src/cmd/file.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@MMexicann
MMexicann marked this pull request as ready for review November 21, 2026 19:06
@autocraft-bot autocraft-bot Bot added the bugfix Fixes something that is broken: wrong result, crash, data loss label Nov 21, 2026

@autocraft-bot autocraft-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review (Claude Opus 5.5). Not a maintainer decision.

No blocking problems found (not certain).

PDF export now returns a bad-parameters error for slides values that are not a list or a range string. Omitted, null and blank values still select all visible slides.

  • crates/engine/src/cmd/file.rs:402-403: arm order is right. Non-blank strings are handled by the guarded arm, blank strings and null fall through to None, and every other JSON type returns BadParams.
  • crates/engine/src/cmd/file.rs:835-846: the test checks the error variant, the command name and that the existing destination keeps its bytes. It removes the scratch directory before asserting, so a failure does not leave files behind.
  • crates/engine/src/cmd/file.rs:400: array entries that are not non-negative integers are still dropped silently. A list such as ["1"] gives an empty selection rather than an error; that could be a follow-up.
  • Other exporters that accept a slides option may share the old fallback and would need the same change.

Claims checked:

  • verified: A number, boolean or object slides value now returns a bad-parameters error instead of exporting every visible slide. (crates/engine/src/cmd/file.rs:403 Some(_) => return Err(bad("file.export", ...)) catches every remaining JSON type. The test at crates/engine/src/cmd/file.rs:840-843 asserts En…
  • verified: Omitted, null and blank range values keep their previous meaning (no slide filter). (crates/engine/src/cmd/file.rs:401 handles non-blank strings first. crates/engine/src/cmd/file.rs:402 None | Some(Value::Null | Value::String(_)) => None maps omitted, null and blank strings to None, as the old `_…
  • verified: The original code treated invalid types as an omitted selector. (The removed line at crates/engine/src/cmd/file.rs:402 (_ => None) mapped every non-array, non-blank-string value to None.)
  • unverified: The error is reported before the destination is written, so an existing file stays unchanged. (The file.export call site that orders pdf_options before the write is not in the diff. The new test at crates/engine/src/cmd/file.rs:835-846 asserts the original bytes remain after the failed export.)

Reviewed at 7b98875.

Recommendation: merge, after a maintainer's decision.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes something that is broken: wrong result, crash, data loss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant