The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 13:30 UTC
fix(server): decode escaped XLSX attachment text (#36849)
Co-authored-by: Grok 4.7 <noreply@x.ai> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 18:51 UTC
16c66605e68a915f606642bfcfb464728ee86838
2 files changed
+36
-3
apps/server/src/provider/documentTextWorker.ts
+20
-3
@@ -114,6 +114,23 @@ function* text(node: XmlNode): Generator<string, void> {
114
else yield* text(child);
115
}
116
}
117
+// SpreadsheetML `t` and `v` values are ST_Xstring: `_xHHHH_` is one UTF-16 code unit, and an
118
+// escaped lead underscore (`_x005F_xHHHH_`) keeps the literal `_xHHHH_`. Decoded in one pass.
119
+function* xstringText(node: XmlNode): Generator<string, void> {
120
+ if (HIDDEN.has(node.name)) return;
121
+ if (node.name !== "t" && node.name !== "v") {
122
+ for (const child of children(node)) yield* xstringText(child);
123
+ return;
124
+ }
125
+ yield node.children
126
+ .filter((child) => typeof child === "string")
127
+ .join("")
128
+ .replaceAll(
129
+ /_x005[Ff]_(x[\dA-Fa-f]{4}_)|_x([\dA-Fa-f]{4})_/g,
130
+ (_, literal?: string, hex?: string) =>
131
+ literal ? `_${literal}` : String.fromCharCode(Number.parseInt(hex!, 16)),
132
+ );
133
+}
134
function* paragraphs(node: XmlNode): Generator<TextPart, void> {
135
if (HIDDEN.has(node.name)) return;
136
for (const child of node.children) {
@@ -542,10 +559,10 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
559
const raw = value?.children.find((child) => typeof child === "string") ?? "";
560
if (cell.attrs.t === "s") {
561
const shared = strings[Number(raw)];
545
- if (shared) yield* inCell(text(shared));
546
- } else if (cell.attrs.t === "inlineStr") yield* inCell(text(cell));
562
+ if (shared) yield* inCell(xstringText(shared));
563
+ } else if (cell.attrs.t === "inlineStr") yield* inCell(xstringText(cell));
564
else {
548
- if (value && hasCellText(value)) yield* inCell(text(value));
565
+ if (value && hasCellText(value)) yield* inCell(xstringText(value));
566
else for (const formula of all(cell, "f")) yield* inCell(text(formula));
567
const formatId = formats[Number(cell.attrs.s ?? 0)]?.attrs.numFmtId;
568
const format = formatId ? customFormats.get(formatId) : undefined;
apps/server/src/provider/userInputAttachments.test.ts
+16
@@ -797,6 +797,22 @@ describe("question answer paths", () => {
797
expected: ["## Sheet: Phonetics", "東京\t東京"],
798
absent: ["とうきょう"],
799
},
800
+ {
801
+ ext: "xlsx",
802
+ bounded: true,
803
+ parts: {
804
+ "xl/workbook.xml": '<workbook><sheet name="Escapes" r:id="a"/></workbook>',
805
+ "xl/_rels/workbook.xml.rels":
806
+ '<Relationships><Relationship Id="a" Target="worksheets/a.xml"/></Relationships>',
807
+ "xl/sharedStrings.xml":
808
+ "<sst><si><t>first_x000D_\nsecond</t></si><si><t>_x005F_x0041_</t></si><si><t>_x005F_x005F_x0041_</t></si><si><r><t>Bold_x000D_</t></r><r><t>_x005F_x000D_</t></r></si><si><t>&_xnothex_ cap_X0041_ _x000d_ tail</t></si></sst>",
809
+ "xl/worksheets/a.xml":
810
+ '<worksheet><row><c t="s"><v>0</v></c><c t="s"><v>1</v></c><c t="s"><v>2</v></c><c t="s"><v>3</v></c><c t="s"><v>4</v></c></row><row><c t="inlineStr"><is><t>_x005F_x005F_</t></is></c><c t="inlineStr"><is><t>first_x000D_second</t></is></c><c t="str"><f>A1</f><v>Total_x000D_due</v></c></row></worksheet>',
811
+ },
812
+ expected: [
813
+ "## Sheet: Escapes\nfirst second\t_x0041_\t_x005F_x0041_\tBold _x000D_\t&_xnothex_ cap_X0041_ tail\n_x005F_\tfirst second\tTotal due",
814
+ ],
815
+ },
816
{
817
ext: "xlsx",
818
bounded: true,