Skip to content

Commit ea23248

Browse files
committed
docs(rest): state the one stored-value shape the CSV round trip does not return unchanged (#25078)
Claude-Session: https://claude.ai/code/session_01LmjU2x1faLZ39DVTFyVca6 Co-authored-by: Claude <noreply@anthropic.com>
1 parent b4de41f commit ea23248

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎.changeset/25078-csv-text-cell.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Metadata-protocol: none (a REST export's bytes and a REST import's parse; nothin
1414
The CSV export (`GET /api/v1/data/:object/export?format=csv`) wrote every text cell exactly as stored, so a cell whose leading character the program the file is opened in interprets was read there as something other than text. The rule below is defined once, in `csvTextCellNeedsMark` (`packages/rest/src/export-format.ts`), and both directions read it.
1515

1616
- **The export.** A CSV text cell whose first character is one of a small fixed set that its consumer interprets is written with one apostrophe (U+0027) in front of its content, before the usual RFC-4180 quoting. A text cell is a string in a column whose field is not declared numeric, boolean, date or datetime, a header label, or a reference field's display title; with no field metadata (the raw path) every string cell is one. A cell made only of digits, spaces and the characters a signed number or a phone number is written with is never marked, so phone numbers and signed amounts are byte-identical.
17-
- **The import.** `parseCsvToRows` removes exactly one leading apostrophe from a cell, header row included, when the rest of the cell is one the export would mark. It serves the sync import (`POST /api/v1/data/:object/import`), the async import job (`POST /api/v1/data/:object/import/jobs`) and plugin-auth's admin user import (`POST /api/v1/auth/admin/import-users`), with an inline mapping or a named one. So a CSV exported and imported back returns every stored value.
18-
- **A user-authored cell** that is an apostrophe followed by a cell the export would mark now imports without that apostrophe; the file cannot tell it from an exported one. A cell beginning with an apostrophe followed by anything else imports unchanged.
17+
- **The import.** `parseCsvToRows` removes exactly one leading apostrophe from a cell, header row included, when the rest of the cell is one the export would mark. It serves the sync import (`POST /api/v1/data/:object/import`), the async import job (`POST /api/v1/data/:object/import/jobs`) and plugin-auth's admin user import (`POST /api/v1/auth/admin/import-users`), with an inline mapping or a named one. So a CSV exported and imported back returns the stored value, with the one exception in the next point.
18+
- **A cell that begins with an apostrophe** followed by a cell the export would mark now imports without that apostrophe; the file cannot tell it from an exported one. That holds for a user-authored cell, and for a stored text value of that shape, which the export writes unchanged, so it comes back without its leading apostrophe. A cell beginning with an apostrophe followed by anything else imports unchanged.
1919
- **Measured.** A value beginning with TAB or CR is marked; the import removes the mark, and the default `trimWhitespace: true` then trims the leading TAB or CR exactly as it did before. With `trimWhitespace: false` it returns exactly.
2020
- **Unchanged.** Every other cell; numeric, boolean, date and datetime cells; the xlsx and json export formats; json and xlsx import payloads.
2121
- **What to do.** Nothing for a file that goes back through these import doors. A program that reads the CSV export some other way and needs the stored text applies the same reversal: remove one leading apostrophe from a cell whose rest satisfies `csvTextCellNeedsMark`.

‎packages/rest/src/data-action-routes.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,8 @@ export function registerDataActionEndpoints(this: DataActionRouteHost, basePath:
894894
// interpret is written in a form that consumer reads as text, by the CSV
895895
// text-cell rule (`markCsvTextCell`, `./export-format.ts`), and the CSV
896896
// import parse reverses exactly that (`parseCsvToRows`), so the file
897-
// re-imports to the stored value. xlsx and json are unaffected.
897+
// re-imports to the stored value (one exception: `unmarkCsvTextCell`).
898+
// xlsx and json are unaffected.
898899
//
899900
// [#24945] Boolean / toggle cells are written in the language of the
900901
// header row: `templateText(locale).booleanWords` (yes / no, or 是 / 否 for

‎packages/rest/src/export-format.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ export function headerLabel(field: string, metaMap: Map<string, ExportFieldMeta>
212212
// ({@link markCsvTextCell}, called by the CSV writer `rowsToCsv` in
213213
// `./rest-server.ts`). The CSV import parse (`parseCsvToRows` in
214214
// `./import-prepare.ts`) reverses exactly that ({@link unmarkCsvTextCell}), so
215-
// an export → import round trip returns the stored value.
215+
// an export → import round trip returns the stored value, with the one
216+
// exception {@link unmarkCsvTextCell} states.
216217
//
217218
// Scope, by construction: CSV only — the xlsx and json formats and the json
218219
// import door never read this rule. Which cells are TEXT cells is the writer's
@@ -259,7 +260,10 @@ export function markCsvTextCell(text: string): string {
259260
* when the remainder satisfies {@link csvTextCellNeedsMark}, and returns every
260261
* other cell unchanged. Applied to every cell of a parsed CSV, header row
261262
* included, so a user-authored cell of that same shape loses its leading mark
262-
* too: the file cannot tell the two apart, and the rule is one rule.
263+
* too: the file cannot tell the two apart, and the rule is one rule. The same
264+
* holds for a STORED text value of that shape — the writer leaves it as is
265+
* (its first character is the mark, not a trigger), so it is the one value an
266+
* export → import round trip does not return unchanged.
263267
*/
264268
export function unmarkCsvTextCell(cell: string): string {
265269
return cell.startsWith(CSV_TEXT_CELL_MARK) && csvTextCellNeedsMark(cell.slice(CSV_TEXT_CELL_MARK.length))

0 commit comments

Comments
 (0)