Repository navigation
Studio: decode escaped text in spreadsheet previews - #16592
Conversation
|
Thanks @DimitriChrysafis. XLSX previews and Library thumbnails showed SpreadsheetML escapes as text, so a cell with a Windows line break read I pushed I compared main and this PR on 1,845 real workbooks: the Apache POI, calamine, ExcelJS and ClosedXML test files, plus XlsxWriter's reference files saved by Excel. Across 1.17 million cells, the only changes are escapes that now decode, in 11 files. Where the source strings are known:
The new tests fail on main and pass here, and the office viewer, attachment preview and server document attachment tests pass (101). Mirror CI is clear at The one cell still off in the table is older than this PR: the reader keeps a literal |
## What was broken Spreadsheet previews decode Excel's `_xHHHH_` text escapes after #16592, but RAG ingestion uses a separate reader and still indexes the encoded strings. Stored text differs from the preview, and lexical searches can miss the decoded cell contents. This is the backend follow-up noted in the merge comment on #16592. ## Repro 1. On main at `91be10960`, put `Zebra_x006D_arker` in an XLSX shared string, inline string or cached formula result. 2. Upload it for RAG indexing. Ingestion completes, but the stored text still contains the escape. 3. Search for `zebramarker`. There are no lexical matches. ## Fix Decode each text run before joining it, preserving quoted underscores and literal uppercase `_X` sequences. Combine UTF-16 surrogate pairs after joining runs, and replace unmatched surrogate units so the result remains valid UTF-8 for indexing. Cached formula strings use the same decoder. Number and error cells are unchanged. ## Test Nineteen regression cases fail before the fix; all 21 selected cases pass afterward. Coverage includes shared, inline and cached strings, rich-run boundaries, phonetic hints, quoted escapes, supplementary Unicode, and Strict OOXML. Upload-to-FTS tests cover `.xlsx`, `.xlsm`, `.xltx` and `.xltm`, using stub embeddings with the real ingestion and SQLite paths. From `studio/backend`: ```text $ python -m pytest -q --tb=short --timeout=330 tests/test_rag_office_formats.py 161 passed in 4.57s ``` ```text $ python -m pytest -q --tb=short -n 4 --dist loadgroup --timeout=330 tests/test_rag_office_formats.py tests/test_rag_parsing.py tests/test_rag_ingestion.py tests/test_rag_retrieval.py 333 passed, 1 skipped in 7.94s ``` The skip is the opt-in real-embedder test. Separately checked 16 exact string round trips through XlsxWriter-generated shared-string and inline-string workbooks, including control characters and escape-looking literals. All seven repository checks and the pinned pre-commit formatter pass. No schema or dependency changes.
What was broken
XLSX previews display Excel's escaped text literally. A cell containing a Windows-style line break shows
_x000D_, and a literal_x000D_shows its_x005F_quoting prefix. This affects both shared and inline cell strings, including Library thumbnails.Repro
81dc73ac43b3bb487820752a4e749f6cf2c3f05f.worksheet.write_string(0, 0, "First\r\nSecond").First_x000D_instead of preserving the original cell text.The regression tests reproduce this without a browser or external workbook dependency.
Fix
Decode SpreadsheetML text escapes after XML entities, within each text run and cached string value. Consume escaped literal tokens whole so their trailing underscore cannot be decoded again. This follows Excel's escaped-string rules without changing formulas, CSV text, or number formatting.
Test
Two regression tests cover shared strings, inline strings, cached formula strings, carriage returns, tabs, surrogate pairs, literal escape-looking text, XML entities, and rich-text run boundaries. Both tests fail before the fix.
From
studio/frontend:The full frontend suite reports 14,785 passing tests, no failures, and one Windows-only skip on macOS. Locale parity, typecheck, build, bundle budget, and all seven repository lint commands also exit successfully. Separately checked XlsxWriter's shared and inline workbooks, including overlapping literal escape sequences.