Repository navigation
CSV export: opt-in values: true writes raw cell values (#2648) - #2666
Conversation
…on (storytold#2648) The default stays Excel's displayed text, byte for byte.
… parts; guard the file test on wasm32
…ion that formats the value
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Date-format shape crates/numfmt/src/lib.rs |
NumberFormat::date_shape identifies whether a selected date format displays calendar parts, time parts, or both. It returns None for non-date and elapsed-time formats. |
Raw-value CSV serialization crates/engine/src/io.rs, crates/engine/src/cmd/file.rs, crates/engine/src/tests.rs, docs/file-format-parity.md |
file.exportCsv uses csv_values_bytes when values is true. The serializer uses the workbook delimiter or a comma by default, writes text as stored, and formats applicable dates and times as ISO 8601. Tests cover both export modes, and the parity document records the option. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant ExportCsv as file.exportCsv
participant CsvValuesBytes as csv_values_bytes
participant Workbook
ExportCsv->>CsvValuesBytes: Pass workbook when values is true
CsvValuesBytes->>Workbook: Read active-sheet values and export settings
Workbook-->>CsvValuesBytes: Return values, delimiter, and date metadata
CsvValuesBytes-->>ExportCsv: Return CSV bytes
Suggested reviewers: echelon, marcoarnulfo, mouhand-kaddo
Merge Risk: 
Minimal · up to f4f48
-
The opt-in export preserves raw values as documented. No actionable merge-blocking issue remains after normal checks.
Security architecture risk: 
Moderate · up to f4f48
-
Default exports remain unchanged, and raw output requires an explicit request. However, raw export can expose formula-leading text previously hidden by display formatting. A recipient opening that output in a spreadsheet may interpret those fields as formulas. The effect is limited to the requested export and depends on how the recipient consumes it; no broader privilege expansion was established.
Retained concerns
- Medium · security · inferred: Opt-in raw CSV export can newly expose formula-leading stored text that display formatting previously masked. CSV quoting preserves field structure but does not prevent a downstream spreadsheet from interpreting that text as a formula. This is a conditional change in effective exposure, not a claim that all CSV formula exposure originated in this PR.
Security review details
-
Security Blast Radius
- inferred — The supported attack scope is attacker-influenced stored text in the exported sheet, an explicit raw-export request, and a recipient application that evaluates CSV fields as formulas. No new execution authority, cross-tenant access, or additional service exposure was established.
Security Findings and Attack Paths
- inferred — The retained injection finding has a narrower PR-specific case: stored text such as =1 can display as safe=1 under a text format such as ;;;"safe"@, but raw export emits =1. Spreadsheet interpretation is downstream and was not demonstrated here. Formula-leading text already visible under ordinary formatting was exportable before this PR; that broader exposure predates the change.
Trust Boundaries and Controls
- observed — The registered command requires an open document, and raw mode requires an explicit boolean true. These limit activation but do not neutralize formula text. The inspected registration and handler do not establish the authentication or authorization policy of external command callers.
Resilience and Maintainability Implications
- observed — The new serializer completes before the existing output-write transition. That writer uses an exclusive temporary file, writes and flushes it, then renames it, with cleanup on handled failures. The PR does not introduce a separate partial-write or rollback mechanism; crash recovery and cross-platform replacement semantics were not independently verified.
Hardening Proposals
- proposed — Keep raw preservation distinct from spreadsheet-safe consumption: document the formula-interpretation boundary and consider a separately named safe-export policy or downstream import-as-text handling. Silently altering stored text in raw mode would conflict with its stated contract.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
FredApps
left a comment
There was a problem hiding this comment.
Reviewed at SHA f4f48f3.
What it does: file.exportCsv takes an optional values param (#2648). With values: true it writes raw cell values for automation: numbers at full precision, date/time cells as ISO 8601, TRUE/FALSE, error text, text as stored. Without it, or with values: false, it takes the unchanged save_bytes path, so the default stays byte-identical to Save As CSV (displayed text). Supporting pieces: io::csv_values_bytes and iso, and NumberFormat::date_shape in numfmt, which reports whether the section that formats a value shows calendar and/or time parts and returns None for non-dates and for elapsed codes like [h]:mm; docs and the command's params text are updated.
Checked (whole diff read): the new path only triggers for ext == "csv" with a truthy values; non-finite numbers and non-numbers fall back to the existing text rendering; date vs time-only vs date-time is decided from the format section that applies to the value (so [>=3]yyyy-mm-dd;[<3]hh:mm picks per value), milliseconds are appended only when non-zero, elapsed formats stay numeric (1.5); the test pins default == file.saveBytes csv bytes, values:false == default, and a 13-cell raw row including date, datetime, time-only, 1-day time, [h]:mm, conditional sections, a comma string and an error.
Not verified: I did not run the tests (the PR says only cargo fmt --check was run locally); the hosted gate is green at this head. Time-only cells larger than one day print the time of day (a value of 1 shows 00:00:00), which matches what the format displays but loses the day count; fine for this opt-in mode but worth knowing.
|
Landed in main (75f7056). Thank you for the contribution, @Harrison-Booth! |
What was wrong: automation callers (MCP, CLI) of file.exportCsv only get displayed text (currency strings, rounded numbers), which loses data. Excel's own Save As CSV writes displayed text too, so that default is Excel parity and is unchanged.
Fix: file.exportCsv takes an optional values param. values: true writes raw values: numbers at full precision, dates and times as ISO 8601, TRUE/FALSE, error text, text as stored. Without it, or with values: false, the output is the same bytes as before. The param is in the command's params doc (so MCP and the catalog show it) and in docs/file-format-parity.md, which also said we wrote raw values (stale).
Verified: cargo fmt --check only. The new test (tests.rs) checks the default export equals Save As CSV bytes, values: false equals the default, and the raw output for currency, rounded, date, datetime, time, bool, quoted text and error cells. Not run locally (fork CI runs the suite). Not re-checked in real Excel: the test asserts only GridCraft's own output; Excel's displayed-text behaviour is as recorded in earlier observation.
🤖 Generated with Claude Code
Summary by CodeRabbit