fix(shared): preserve surrogate pairs in truncated CSV cells #27497
main fromrefs/pull/27497/head·merged by maria-rcks View on GitHubProblem#
CSV and TSV table previews can end a truncated cell with a replacement character. The parser limits cells by UTF-16 code units, so a surrogate pair crossing the limit is split. For example, 1,999 ASCII characters followed by an emoji produces a lone high surrogate at the default 2,000-unit limit used by mobile previews.
Change#
Keep one extra code unit while parsing each cell, then trim at a complete surrogate-pair boundary. The output remains within the existing limit and preserves the original prefix. Parsing of subsequent columns, rows, quoted fields and escaped quotes stays unchanged.
Scope and approval#
This is a small, focused fix for an obvious text-truncation defect under CONTRIBUTING.md's exception, without a prior issue or discussion. No configuration, workflow, product default or UI component changes.
Verification#
Linux x86_64, Node 26.12.1, base 32ecd71726fee16f335484c1f95cbce126d461f6.
- Four new regression cases fail on the original parser: quoted and unquoted cells for both CSV and TSV.
- All 17 focused parser tests pass after the fix, including an exactly fitting emoji, truncation after a complete pair, escaped quotes, BMP characters and subsequent columns/rows.
- Shared-package typecheck passes.
git diff --checkpasses. - 2,000 deterministic generated CSV/TSV fixtures across quoted fields, separators, line breaks, BMP characters, emoji and limits 1–8 passed.
vp run check:changed upstream/mainpassed formatting, lint, both knip passes and 18 tests across two adjacent files. Its aggregate 33-package typecheck was blocked when the environment could not start its seccomp supervisor for the desktop typecheck. The aggregate check is not reported as passed.- No integrated web/mobile client or visual verification performed. The regression checks call the production parser directly. Native preview appearance and cross-device behavior remain unverified.
AI assistance: OpenAI model (exact model identifier/version is not exposed by this runtime). Harness: dot / OpenAI Codex.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Note
Written by
gpt-6.1-solon behalf of Mariathanks
macodev00. the bounded lookahead and complete-pair cut already form a small, correct fix, so i kept your implementation and all existing regressions. i merged current main without rebasing or dropping your commit. the final diff remains two files, 43 additions and 2 deletions.verification at
e9effc376982659532c91c445366dbc5c81003ba:- reproduced all four quoted/unquoted csv/tsv failures against main
e5909e53c32a9d5b51caf6352d1f17fd73e86db7before applying the fix. - all 17 parser tests pass. blacksmith
vp run check:changed github/mainpasses format, lint, both knip passes, 33-package typecheck, and 18 tests. - chrome runtime checks through the served production parser return well-formed 1,999-unit cells and retain subsequent columns and rows in all four cases.
- two independent source reviews found no issues on this head.
native mobile rendering remains unverified on this linux vm. the real web attachment preview was exercised before and after with matching csv data; emoji and later fields remain intact. these images show nearby web behavior, not the mobile truncation fix. the web worker rejects oversized records before its cell limit, so the mobile-limit regression is established by the failing-before parser tests.


- reproduced all four quoted/unquoted csv/tsv failures against main
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
checked unchanged head
e9effc376982659532c91c445366dbc5c81003baagainstgithub/mainat5fe18d79ac. each checkout hadvp iand its own running dev code, with only one dev server running at a time. used isolated state created for this task.through the real web app in google chrome, driven with the repository's playwright, created a local git project and used codex
gpt-6.1-solthrough the local proxy to create csv, tsv and text files. a second sol turn on the pr read and checked those files. both turns completed in 12 seconds.the web file previews retain all five rows and three columns, the 1,999-character prefix followed by emoji, exactly fitting emoji, escaped quotes, accented text and every later field. switching tsv between table and source, toggling source word wrap, returning to table, opening plain text and returning to csv worked.
separately imported each running dev server's production parser into chrome and supplied those same provider-created files at the unchanged default limit. this is a parser runtime check, not native client proof:
main: quoted + unquoted CSV/TSV (4 cases) length=2000, isWellFormed=false, final code unit=0xd83d pr: same 4 cases length=1999, isWellFormed=true, truncated=true both: exactly fitting emoji length=2000, isWellFormed=true both: escaped quotes, accented text, later columns and final row retained blacksmith: vp i && vp test run packages/shared/src/delimitedPreview.test.ts 1 test file passed; 17 tests passed pr head CI: 28 successful, 0 failing, 0 pendingthese matching-data screenshots show neighboring web behavior. they do not show the mobile truncation change.



Not verified#
the changed 2,000-unit truncation is reachable in native mobile workspace, attachment and zip-entry previews. no android device is attached, and the device tool returned "agent device access is turned off for this environment." native android and ios rendering remain unverified, including reproducing the original replacement character in a native client.
normal web inputs cannot reach the changed truncation boundary: the first-screen input is bounded before parsing at the same limit, and the worker rejects records above its byte limit before reaching its cell length limit. therefore the successful parser checks and web interactions do not complete the requested end-to-end verification of this mobile fix. desktop electron and remote/tunnel connections were not exercised. no source changes or pushes were needed for the checks performed.
maria-rcks merged thisc018660
maria-rcks closed this
Sign in to join this conversation.
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
6ee82d76-c355-41b4-8a5a-6f9ab8c68380Reviewing files that changed from the base of the PR and between 68892c0436a5fe3c479db0d3ba90c7c537e5fdcb and e9effc376982659532c91c445366dbc5c81003ba.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review.
6b3297ea-9354-49bd-9fc1-8763942a643eReviewing files that changed from the base of the PR and between 32ecd71726fee16f335484c1f95cbce126d461f6 and 68892c0436a5fe3c479db0d3ba90c7c537e5fdcb.
packages/shared/src/delimitedPreview.test.tspackages/shared/src/delimitedPreview.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Walkthrough
parseDelimitedPreviewtrims cells that exceed the maximum length while avoiding splits within UTF-16 surrogate pairs. New tests cover comma and tab delimiters, escaped quotes, and Unicode boundary cases.Changes: Delimited preview truncation
packages/shared/src/delimitedPreview.ts,packages/shared/src/delimitedPreview.test.tsendCellwithout splitting a surrogate pair. Tests cover quoted and unquoted cells, comma and tab delimiters, and truncation boundaries.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related PRs
maxCellLengthbehavior toparseDelimitedPreview, which this change adjusts for UTF-16 truncation.Suggested reviewers:
maria-rcksMerge Risk:
Minimal · previous review
68892No merge-blocking issue was identified in the preview truncation change.
Pre-merge checks:
4
Full details: Description check
Explanation
The description covers the problem, implementation, scope and approval rationale, focused verification, blocked checks, and unverified areas. It provides concrete test results and does not overstate validation.
Finishing Touches
🧪 Generate unit tests (beta)