Skip to content

Export: a path whose extension names the format is written as given - #4370

Open
Hamza0101 wants to merge 1 commit into
storytold:mainfrom
Hamza0101:fix/export-keeps-format-extension
Open

Hamza0101 wants to merge 1 commit into
storytold:mainfrom
Hamza0101:fix/export-keeps-format-extension

Conversation

@Hamza0101

@Hamza0101 Hamza0101 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4355

What was wrong

export in crates/engine/src/cmd/file.rs serves file.exportHtml and file.exportCsv. It kept the given path only when it ended with exactly .html or .csv, case-sensitively, and otherwise appended the extension. So page.htm, page.HTML and data.CSV were written as page.htm.html, page.HTML.html and data.CSV.csv. The commands reported success, and the requested files never appeared. file.saveAs with the same paths keeps them, as the issue shows.

What changed

  • A path keeps its name when its extension names the export's format. That uses io::FileKind::from_path, the same mapping that open and save use: it ignores letter case and knows .htm as HTML.
  • Any other path still gets the format's extension, as before: a bare name, or page.csv for an HTML export.

QA report

Main vs branch, end to end (gridcraft-cli run)

Each row is a fresh run that sets A1 and calls the command with the path in an empty folder. main is a gridcraft-cli built from origin/main (abcfc191); the branch is this PR (1d55e2c1).

Command Path asked for main writes this PR writes
file.exportHtml page.htm page.htm.html page.htm
file.exportHtml page.HTML page.HTML.html page.HTML
file.exportCsv data.CSV data.CSV.csv data.CSV
file.exportHtml plain.html (control) plain.html plain.html
file.exportCsv bare (control) bare.csv bare.csv
file.saveAs book.HTM (the issue's comparison) book.HTM book.HTM

The folder held exactly those files afterwards, with nothing written under a doubled extension on the branch. The returned path names the file written in both builds.

Test

tests::exports_keep_a_path_whose_extension_names_the_format writes:

  • for HTML: page.htm, page.HTML, page.Htm, page.html, a bare page (gets .html) and page.csv (gets .html);
  • for CSV: data.CSV, data.csv, a bare data (gets .csv), and data.htm and data.txt (both get .csv).

For each, it checks the returned path and that the file holds the cell, and that no doubled name exists.

Negative control

With the exact lower-case suffix check put back (on top of 1d55e2c1, then restored with git checkout), the test fails at file.exportHtml page.htm: left …/page.htm.html, right …/page.htm.

Gate (macOS arm64)

Step Result
cargo fmt --all -- --check clean
cargo clippy -p gridcraft-engine --all-targets -- -D warnings clean
cargo test -p gridcraft-engine -p gridcraft-xlsx 1005 (+1 ignored) + 120 + 7 + 374 passed, 0 failed

Not covered

  • .txt for CSV: data.txt still gets .csv added. GridCraft reads .txt as tab-separated, so it isn't the CSV format's extension; that's unchanged from main.
  • Case-insensitive file systems: this Mac's APFS treats page.HTML and page.html as one file. The test's cases still hold there, and on Linux CI they're distinct files.
  • Windows: the issue was reproduced on Windows. I ran macOS only; the logic doesn't depend on the platform.
  • cargo xtask ci: I didn't run the full cargo xtask ci (wasm, layers, the other crates).

Summary by CodeRabbit

  • Bug Fixes
    • Export filenames now retain extensions that match the selected format, including case variations and supported alternatives. A format extension is added when the filename has no matching extension.
  • Tests
    • Added coverage for export filename handling and verifying that exported files are written to the returned path.

file.exportHtml and file.exportCsv compared the path with ".html" or ".csv" exactly, so page.htm, page.HTML and data.CSV were written as page.htm.html, page.HTML.html and data.CSV.csv, and the requested files never appeared. A path whose extension names the export's format, in any case or spelling, now keeps it, as file.saveAs does; any other path still gets the format's extension. Fixes storytold#4355.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Export recognizes extensions supported by the requested format, including case variants and alternate spellings. It appends the format extension when the path has no matching format. A native-only test checks returned paths and written files.

Changes: Export path handling

Layer / File(s) Summary
Recognize export extensions
crates/engine/src/cmd/file.rs, crates/engine/src/tests.rs
Export preserves paths whose extensions resolve to the requested FileKind and appends the requested extension otherwise. The native-only test covers HTML and CSV paths, returned paths, and written files.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: echelon, vangel76

Merge Risk: Minimal · up to 1d55e

Exports now keep a requested filename when its extension matches the format, including .htm, .HTML and .CSV. Other paths still get the format extension appended. No merge-blocking risk was identified.

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 states the main behavior change: a path whose extension already names the export format is kept as given. The raw summary confirms the change in crates/engine/src/cmd/file.rs (FileKind-based…
Linked Issues check Passed Directly linked issue #4355 requires that file.exportHtml and file.exportCsv keep a requested path whose extension names the export format. Required cases: .htm and .HTML for HTML, and .CSV for CSV. L…
Out of Scope Changes check Passed The whole-PR diff against merge base abcfc19 changes two files. crates/engine/src/cmd/file.rs changes only the target-path decision in export, with a comment that cites #4355. crates/engine/src/tests…
Full details: Title check

Explanation

The title states the main behavior change: a path whose extension already names the export format is kept as given. The raw summary confirms the change in crates/engine/src/cmd/file.rs (FileKind-based extension detection for export) and the added test in crates/engine/src/tests.rs. The title is specific and matches the linked issue's request for preserved filenames. It does not mention the case-insensitive or .htm handling, which is a detail and not required.

Full details: Linked Issues check

Explanation

Directly linked issue #4355 requires that file.exportHtml and file.exportCsv keep a requested path whose extension names the export format. Required cases: .htm and .HTML for HTML, and .CSV for CSV. Lowercase canonical suffixes must stay, and suffixless paths must get the format extension.

Implementation at head (crates/engine/src/cmd/file.rs, export): the old check path.ends_with(".{ext}") is replaced. The path is kept when crate::io::FileKind::from_path(path) returns a kind equal to FileKind::from_path("export.{ext}"). Otherwise the extension is appended. Per the PR description and the added test, from_path ignores letter case and maps .htm to HTML. Therefore page.htm, page.HTML and data.CSV keep their names. page.html and data.csv are still kept. A bare name, or page.csv for an HTML export, still gets the extension.

Automated coverage: tests::exports_keep_a_path_whose_extension_names_the_format (crates/engine/src/tests.rs, +35 lines) checks returned paths, file contents and the absence of doubled names for these cases. The author reports a negative control: restoring the exact lowercase check fails the test.

Limits: the repository could not be read in this review, so from_path's case-insensitive and .htm behavior is taken from the PR description and the test, not re-read from source. Windows was not tested by the author, although the issue was reproduced on Windows.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against merge base abcfc19 changes two files. crates/engine/src/cmd/file.rs changes only the target-path decision in export, with a comment that cites #4355. crates/engine/src/tests.rs adds one native test for export filenames. Both changes serve the #4355 objective. No unrelated behavior change is shown. The PR description also states that .txt for CSV is unchanged, so no unrelated change is introduced there.

Finishing Touches

Generate unit tests (beta)

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

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between abcfc19 and 1d55e2c.

Files selected for processing: 2

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

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

emrahoksak pushed a commit to emrahoksak/girdcraft- that referenced this pull request Nov 18, 2026

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit HTML and CSV export append a second extension to valid paths

1 participant