fix(file-parsers): stop deleting non-BMP characters when sanitizing parsed text - #6442
Conversation
…arsed text The unpaired-surrogate strip used a bare [\uD800-\uDFFF] class, which matches UTF-16 code units and so removed both halves of every valid surrogate pair — deleting all emoji, CJK Extension B, and mathematical alphanumerics from parsed output. Match only genuinely unpaired surrogates instead. Also surface PDF truncation inline. Callers read only `content`, so a bounded PDF was indistinguishable from a complete one; it now carries the same `[... ... ...]` marker csv and xlsx already use, via a shared helper. Drop two unused exports, one of which carried the same surrogate bug.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview CSV and XLSX now use that helper for row/size limits (same marker text as before). PDF appends an inline truncation notice when extraction hits parser limits and there is real text; Reviewed by Cursor Bugbot for commit b66c26e. Configure here. |
Greptile SummaryThe PR corrects Unicode sanitization so valid surrogate pairs are preserved and standardizes inline truncation notices across file parsers.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/file-parsers/utils.ts | Replaces blanket surrogate removal with unpaired-surrogate matching, removes unused exports, and adds the shared truncation marker formatter. |
| apps/sim/lib/file-parsers/pdf-parser.ts | Tracks extracted-page coverage and exposes parser-limit truncation in returned content while retaining metadata. |
| apps/sim/lib/file-parsers/pdf-parser.test.ts | Extends bounded-extraction coverage for inline notices, normal PDFs, and text-free multi-page PDFs. |
| apps/sim/lib/file-parsers/utils.test.ts | Covers valid surrogate pairs, malformed surrogates, UTF-8 round trips, control characters, and truncation formatting. |
| apps/sim/lib/file-parsers/csv-parser.ts | Replaces the local row-limit marker construction with the byte-equivalent shared helper. |
| apps/sim/lib/file-parsers/xlsx-parser.ts | Replaces duplicated row and size truncation marker construction with the shared helper. |
Reviews (2): Last reviewed commit: "fix(file-parsers): keep text-free PDFs e..." | Re-trigger Greptile
…t were read Gate the truncation notice on the sanitized, trimmed body: a text-free multi-page PDF collapses to a lone separator, so the previous length check let a notice turn a document callers treat as empty into one that looks like it holds content. Also stop counting a page the budget cut off before it yielded anything, so the notice no longer reports one more page than was shown.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b66c26e. Configure here.
Summary
sanitizeTextForUTF8stripped unpaired surrogates with a bare[\uD800-\uDFFF]class. That matches UTF-16 code units, so it removed both halves of every valid surrogate pair — silently deleting all emoji, CJK Extension B, and mathematical alphanumerics from every parser's output. Now matches only genuinely unpaired surrogates.content, so a bounded PDF was indistinguishable from a complete one. It now carries the same[... ... ...]marker csv and xlsx already used, moved into a sharedtruncationNotice()helper.sanitizeTextArray,hasInvalidUTF8Characters) — the latter carried the same surrogate bug.Before / after:
Type of Change
Testing
New
utils.test.tscovers pair preservation, unpaired-surrogate removal, an unpaired surrogate adjacent to a valid pair, and a UTF-8 round-trip; verified all four fail against the previous implementation. Confirmed the csv/xlsx notices are byte-identical to the strings they produced before, and that PDF output is unchanged for documents within budget (including a 2000-page fixture). 85 parser + 599 consumer tests pass.Checklist