Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): preserve surrogate pairs in truncated CSV cells #27497

Mergedmacodev00(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/27497/headmerged by maria-rcks View on GitHub

Problem

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 --check passes.
  • 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/main passed 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

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      Run configuration
      Commits

      Reviewing 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_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • Trigger review

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between 32ecd71726fee16f335484c1f95cbce126d461f6 and 68892c0436a5fe3c479db0d3ba90c7c537e5fdcb.

      Files selected for processing: 2
      • packages/shared/src/delimitedPreview.test.ts
      • packages/shared/src/delimitedPreview.ts

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

      Walkthrough

      parseDelimitedPreview trims 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

      Layer / File(s)Summary
      Cell truncation and boundary tests
      packages/shared/src/delimitedPreview.ts, packages/shared/src/delimitedPreview.test.ts
      The parser allows an append at the length limit, then trims an overlong cell in endCell without 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

      • pingdotgg/t3code#21466: Adds the maxCellLength behavior to parseDelimitedPreview, which this change adjusts for UTF-16 truncation.

      Suggested reviewers: maria-rcks

      Merge Risk: Minimal · previous review 68892

      No merge-blocking issue was identified in the preview truncation change.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title is concise, specific, and accurately describes the main change: preserving surrogate pairs when truncating CSV cells. It also follows the conventional commit format.
      Description checkPassedThe 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 v…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      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)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
    3. Note

      Written by gpt-6.1-sol on behalf of Maria

      thanks 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 e5909e53c32a9d5b51caf6352d1f17fd73e86db7 before applying the fix.
      • all 17 parser tests pass. blacksmith vp run check:changed github/main passes 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.

      web attachment preview with main parser, matching csv data

      web attachment preview with fixed parser, matching csv data

    4. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      checked unchanged head e9effc376982659532c91c445366dbc5c81003ba against github/main at 5fe18d79ac. each checkout had vp i and 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-sol through 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 pending

      these matching-data screenshots show neighboring web behavior. they do not show the mobile truncation change.

      main web csv preview with matching provider-created data

      pr web csv preview with matching provider-created data

      pr web tsv table and source interaction recording

      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.

    5. maria-rcks merged thisc018660

    6. maria-rcks closed this

Sign in to join this conversation.