Repository navigation
fix(rest): open a csv export with the UTF-8 byte-order mark so Excel reads non-ASCII text - #34357
Conversation
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
Excel reads a csv without the mark in the system ANSI code page, so every non-ASCII header and cell of an export opened garbled. The csv leg now writes U+FEFF once, after the first read and ahead of the header row; json and xlsx are unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
…xport stays empty Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
The export pins that read the csv body as text strip exactly one leading U+FEFF at that read; the byte-identical pins take the mark into their expected bytes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
…ort suites Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
📓 Docs Drift Check2 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 19 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 120fdfca1f2f9e43971f2078f62169889720c6f5 && git checkout 120fdfca1f2f9e43971f2078f62169889720c6f5
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 9e6fee19ea358232196e1f704198612a2de34710 67500498c83365efb8748cd065088e749a34e7bf && git checkout -B drift-repro 9e6fee19ea358232196e1f704198612a2de34710 && git merge --no-ff 67500498c83365efb8748cd065088e749a34e7bf
node scripts/docs-audit/affected-docs.mjs --json 9e6fee19ea358232196e1f704198612a2de34710 |
…der mark The admin user import round trip exports through the real rest export route, which now opens a csv body with one U+FEFF. The header compare strips exactly that one mark; the import still receives the file with its mark, as exported, so the round trip also covers the mark. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kgF3mo9f7LXuv5hac Final head for landing · PR #34357 · 2026-11-16T16:09ZHead-sha:
Generated by Claude Code |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5mww9UksbwbjvM4aYn 席位核对 · PR #34357 · L1-b · 2026-11-16T16:12ZHead-sha: L1 · REWORK(1 项,只改 PR 正文,不动代码) · area o1-C 定稿评论 6921861946 所钉 head;本 PR 首次 L1(继承件)。merge-base 已核、无问题的部分
R1 · 同类缺陷缺去处。 Acceptance notes 的"Not changed here"列了 5 个 Console 端没有 mark 的 CSV writer( 非阻塞:Verification 一节写"51 check-runs, 35 success, 16 skipped",本 head 现在读到 55 / 37 / 18。数字过时了,不影响结论。 落地条款:非受管路径,Clause-② no,没有 |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5mww9UksbwbjvM4aYn 席位核对 · PR #34357 · L1-b · 2026-11-16T16:15ZHead-sha: L1 delta · ACCEPT · 对照 L1 REWORK 6921943962,head 未变。只核 PR 正文。
落地条款:非受管路径,不欠 L2。分支落后 main,合入 main 后把 merge-only delta 发我;本 ACCEPT 作为该 delta 的基线。 |
Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac Co-Authored-By: Claude <noreply@anthropic.com>
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kgF3mo9f7LXuv5hac Final head for landing · PR #34357 · 2026-11-16T16:54ZSupersedes announce 6921861946 (head Generated by Claude Code |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5mww9UksbwbjvM4aYn 席位核对 · PR #34357 · L1-b · 2026-11-16T16:55ZHead-sha: L1 merge-only delta · ACCEPT · area o1-C 定稿评论 6923053928 所钉 head;对照 L1 ACCEPT 6922042068(@
落地条款:非受管路径,由区线程自行落地;不欠 L2。 |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kgF3mo9f7LXuv5hac Landing · PR #34357 · 2026-11-16T16:57Z
State change: ready for review + auto-merge (merge queue). On MERGED, Generated by Claude Code |
Requested by Steedos · project thread
Fixes #34163
Clause-②: no
Metadata-protocol: none (no authorable key or value; the CSV export body gains a leading UTF-8 byte-order mark. The dev confirms against the diff.)
维护者速读
GET /api/v1/data/:object/export导出 CSV 时,文件开头写一个 UTF-8 字节序标记(BOM,EF BB BF),只写一次,放在表头行之前(header=false时放在第一行数据之前)。JSON、XLSX、响应头都不变,没有新参数。charset=utf-8不会跟着文件存到磁盘上。HotCRM 在 18.5.0 上实测复现。Response.text()、浏览器 Blob 下载、平台自己的 CSV 导入都不受影响。完全没有内容的导出仍是 0 字节。回滚即撤销本 PR,不涉及存储数据。packages/rest/src/data-action-routes.ts里UTF8_BOM常量和 CSV 分支的两处首次写入;packages/rest/src/export-csv-utf8-bom-34163.test.ts;packages/rest/src/import-template-route.test.ts里改过的字节级期望值。pnpm --filter @objectstack/rest exec vitest run src/export-csv-utf8-bom-34163.test.ts,预期 1 个文件、8 个用例全部通过。What changes
packages/rest/src/data-action-routes.ts: theformat=csvleg (also the default format) prefixesUTF8_BOM('\uFEFF', spelled as the escape; the file holds no raw EF BB BF bytes) to the body's FIRST write, exactly once: the first chunk (header row, or the first data row underheader=false) or, at zero rows, the authoritative header row. It is written after the first read, as before, so a refused query still answers the 400 envelope. An export that writes nothing (zero rows and no authoritative header) stays a zero-byte file, with no lone mark.format=jsonandformat=xlsx, every response header (Content-Type: text/csv; charset=utf-8,Content-Disposition,X-Export-*) and the closed query set are unchanged; nobomparameter and no option.parseCsvToRows,packages/rest/src/import-prepare.ts), so an exported file re-imports unchanged; pinned..changeset/34163-csv-export-utf8-bom.md:@objectstack/restpatch with both declaration lines.Tests
packages/rest/src/export-csv-utf8-bom-34163.test.ts(8 cases), through the realHonoHttpServerover a realSqlDriver(SQLite), reading the body as BYTES (arrayBuffer()):Response.text()drops a leading mark, so a text read could not tell the fix from the defect.header=false.fields=: one mark, then the header row alone. Zero rows with no authoritative header: zero bytes.[and xlsx withPK: no mark.parseCsvToRowsto the same header names and cells as the same text without the mark.import-template-route.test.tstake the mark into their expected bytes (bytes+ 3,sha256recomputed over the marked body; each old hash was first re-verified against its old text). The round-trip tests that feed the export straight to the import (csv-text-cell-round-trip,export-boolean-locale) still import the file WITH its mark. The list is in Acceptance notes. Two of them (rest.test.ts,rest-14078-invalid-date-total-arm.test.ts) also gain a module-topimport '@objectstack/objectql', whichcheck:test-source-aliasasks of an edited test whose source reaches that dynamic import.packages/restreads the same export body:packages/plugins/plugin-auth/src/admin-import-users.test.ts:802(the rest: one record export format may not neutralize a stored value for the context its consumer reads it in (reach not measured; detail withheld under the disclosure ruling) #25078 export-then-admin-import round trip, caught red by Test Core (7/8) at 4de0e1e). Its header check now strips exactly one leading U+FEFF (anchored regex, spelled as the escape) and the admin import still receives the file with its mark, so this door's round trip covers the mark too. Test-only; plugin-auth publishes only dist, so no changeset. Fixed at 6e2297c.Acceptance notes
csv-text-cell-round-trip.test.ts:171csv.split(...)[0]tocsv.replace(/^\uFEFF/, '').split(...)[0](the import still receives the marked file).admin-import-users.test.ts:802(plugin-auth):csv.split(...)[0]tocsv.replace(/^\uFEFF/, '').split(...)[0](the admin import still receives the marked file); caught by Test Core (7/8) at 4de0e1e.export-boolean-locale.test.ts:153(csvRows),export-hidden-columns.test.ts:92(parseCsv),export-integration.test.ts:178(parseCsv),export-lookup-title-field.test.ts:167(parseCsv): the csv-only parse helper strips one leading mark.export-date-year-pad.test.ts:219,import-business-timezone.test.ts:438,import-date-cell-iso-real-day.test.ts:252,import-datetime-year-below-100.test.ts:254,import-time-cell-fraction.test.ts:302,rest-14078-invalid-date-total-arm.test.ts:202: the csv read before the header compare strips one leading mark.export-json-fields.test.ts:145,:176,:209: the three csv reads (the sharedexportOfalso serves json, so the strip sits at the csv call sites).rest.test.ts:1080,:1232,:1249,:1392,:1402: the in-process csv body reads.import-template-route.test.ts:692-694csvDefault bytes 123 to 126, sha256 26d25190 to f5287f81, text gainsCSV_MARK;:718-720csvFields 54 to 57, 62cd1868 to af30704a;:725-727csvNoHeader 78 to 81, 7f8f78c0 to 696b5d73. csvEmptyNoProjection (0 bytes) unchanged.ui/packages/plugin-list/src/ListView.tsx:5886(client-side fallback),ui/packages/plugin-grid/src/ObjectGrid.tsx:1617,ui/packages/components/src/renderers/complex/data-table.tsx:2309,ui/packages/plugin-report/src/ReportExportEngine.ts:54,ui/packages/app-shell/src/views/IdentityImportPanels.tsx:87. The Console's server export path saves the body withres.blob(), so this fix reaches its files. No other server-side CSV download writer exists inpackages/**; no spec or docs text states the CSV body's first bytes.Verification
Head 6750049 (merge-only round, os-dev-report 6922999882 on #34163): origin/main 9e6fee1 merged into 6e2297c as a plain merge commit, pushed without force; no conflict, no os-regen path. The PR's own diff against the new merge base 9e6fee1 is byte-identical to its diff at 6e2297c against 951ecee (sha256 624ff264, 18 files, +287 / -31). CI at 6750049: 51 check-runs, 35 success, 16 skipped, 0 failed. Test Core (5/8) ran @objectstack/rest fresh: Test Files 414 passed (414), Tests 8564 passed / 350 skipped, export-csv-utf8-bom-34163.test.ts 8 passed. Test Core (7/8) ran plugin-auth fresh: admin-import-users.test.ts 43 passed, Test Files 280 passed, Tests 5762 passed / 11 skipped. @objectstack/rest:typecheck ran fresh in Type Check · workspace and passed. Local test and typecheck runs this round NOT MEASURED (verify-lock queue timeout, 3 tries); CI is the reading of record.
Previous head 6e2297c (fix round, report 6921751590 on #34163): adds only the plugin-auth test fix above on 4de0e1e, pushed without force; not merged with main (mergeable_state clean, the red was this PR's own). CI at 6e2297c: 55 check-runs, 37 success, 18 skipped, 0 failed; Test Core (7/8) ran plugin-auth fresh,
admin-import-users.test.ts43 passed, plugin-auth 280 files / 5762 tests passed. Local test runs and typechecks for this round NOT MEASURED (verify-lock queue timeout, 3 tries); CI at both heads is the reading of record: at 4de0e1e the old line failed (1 failed / 5699 in plugin-auth), at 6e2297c it passes.Previous head 4de0e1e (origin/main 951ecee merged at b9f5979; a driver-less bare-clone
merge-treeprobe answered exit 0, no conflicted path). Stopped by the maintainer's hand-off order: what was not re-run on the final head is named below as NOT MEASURED.Main measured first, then the fix
[ 229, 144, 141 ](the Chinese header), never[ 239, 187, 191 ]; json and xlsx passed.scripts/ablation-replace.mjs; the test imports the route from source, so no dist leg): removing the mark from the first-chunk write gave Tests 4 failed, 4 passed (8); removing it from the zero-row header write gave Tests 1 failed, 7 passed (8), the zero-row case. Both restored: the blob equals HEAD,git diff HEADempty.Suites
pnpm --filter @objectstack/rest testat b9f5979, after a fresh install and a rebuild of the rest closure, under the verify lock: VERDICT command-exit 0, Test Files 414 passed (414), Tests 8560 passed, 350 skipped.import '@objectstack/objectql'to two of the edited test files (check:test-source-alias asked for it):rest.test.tsandrest-14078-invalid-date-total-arm.test.tsgave Test Files 2 passed, Tests 225 passed. The full rest suite on 4de0e1e: NOT MEASURED (stopped by the hand-off order).pnpm --filter @objectstack/rest typecheckat b9f5979: exit 0. eslint--no-inline-configon every touched ts file: exit 0.Derived gates (dispatch-gates --commands, 68 families)
check:dual-build-cjs-loadsexit 3 (prerequisite: the whole workspace unbuilt, nothing measured);check:test-source-aliasexit 1 on the two edited files above, fixed in 4de0e1e, where it answered exit 0.check:dual-build-cjs-loadsincluded). Stopped by the hand-off order;--ranreconciliation: 68 derived, 57 run, 0 NOT-MEASURED, 11 UNRUN: slot-lookup, sourcemap-no-sources-content, system-context-census, test-source-alias, tier-file-adoption, type-check-coverage, type-check-debt, undeclared-dep-imports, vouch-for-reference-callers, watch-hint-literal, where-matcher. Those 11 were exit 0 at b9f5979 except test-source-alias (above); CI carries them.🤖 Generated with Claude Code
https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5