Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: decode escaped text in spreadsheet previews (#16592)
DimitriChrysafisa17bfe91ab6e
diff --git a/studio/frontend/src/components/file-viewer/office.ts b/studio/frontend/src/components/file-viewer/office.tsindex d20e948c32a..81abf07129c 100644--- a/studio/frontend/src/components/file-viewer/office.ts+++ b/studio/frontend/src/components/file-viewer/office.ts@@ -849,10 +849,18 @@ function flattenMarkup(text: string): string {);}+function decodeXstring(text: string): string {+ return text.replace(+ /_x005[fF]_(x[0-9a-fA-F]{4}_)|_x([0-9a-fA-F]{4})_/g,+ (_match, literal?: string, hex?: string) =>+ literal ? `_${literal}` : String.fromCharCode(parseInt(hex!, 16)),+ );+}+function stringText(xmlText: string): string {let out = "";for (const match of flattenMarkup(xmlText).replace(PHONETIC, "").matchAll(TEXT_RUN)) {- out += decodeXml(match[1]!.slice(0, MAX_CELL_BYTES));+ out += decodeXstring(decodeXml(match[1]!.slice(0, MAX_CELL_BYTES)));if (out.length >= MAX_CELL_TEXT) return out.slice(0, MAX_CELL_TEXT);}return out;@@ -933,7 +941,7 @@ function readSheet(let numeric = false;if (raw === "" && formula && !(type === "str" && cached)) value = `=${formula}`;else if (type === "s" || type === "inlineStr" || type === "str") {- value = formatText(type === "s" ? string(Number(raw)) : type === "inlineStr" ? stringText(body) : raw, cellStyle.format);+ value = formatText(type === "s" ? string(Number(raw)) : type === "inlineStr" ? stringText(body) : decodeXstring(raw), cellStyle.format);} else if (type === "b") value = isTrue(raw) ? "TRUE" : "FALSE";else if (type !== "str" && type !== "e" && raw !== "" && Number.isFinite(Number(raw))) {value = formatNumber(Number(raw), cellStyle.format, date1904);diff --git a/studio/frontend/tests/file-viewer-office.test.ts b/studio/frontend/tests/file-viewer-office.test.tsindex b89757a6d27..f3de416a60e 100644--- a/studio/frontend/tests/file-viewer-office.test.ts+++ b/studio/frontend/tests/file-viewer-office.test.ts@@ -113,6 +113,39 @@ test("xlsx: sheet XML read as text", () => {);});+test("xlsx: decodes escaped text in shared, inline and cached formula strings", () => {+ for (const [encoded, expected] of [+ ["First_x000D_\nSecond_x0009_End", "First\r\nSecond\tEnd"],+ ["_xD83D__xDE00_", "\u{1f600}"],+ ["_x005F_x000D_", "_x000D_"],+ ["_x005F_x005F_x000D_", "_x005F_x000D_"],+ ["&_x0041_ _xZZZZ_", "&A _xZZZZ_"],+ ["_X0041_ _X000D_ _x004a_", "_X0041_ _X000D_ J"],+ ]) {+ const [sheet] = readXlsx(workbook(+ `<worksheet xmlns="${MAIN}"><sheetData><row r="1">+ <c r="A1" t="s"><v>0</v></c>+ <c r="B1" t="inlineStr"><is><t>${encoded}</t></is></c>+ <c r="C1" t="str"><f>A1</f><v>${encoded}</v></c>+ </row></sheetData></worksheet>`,+ { "xl/sharedStrings.xml": strToU8(`<sst xmlns="${MAIN}"><si><t>${encoded}</t></si></sst>`) },+ ));+ assert.deepEqual(sheet?.rows[0]?.map((cell) => cell?.text), [expected, expected, expected], encoded);+ }+});++test("xlsx: decodes rich text runs independently", () => {+ const rich = "<r><t>_x00</t></r><r><t>0D_</t></r><r><t>_x000A_end</t></r>";+ const [sheet] = readXlsx(workbook(+ `<worksheet xmlns="${MAIN}"><sheetData><row r="1">+ <c r="A1" t="s"><v>0</v></c>+ <c r="B1" t="inlineStr"><is>${rich}</is></c>+ </row></sheetData></worksheet>`,+ { "xl/sharedStrings.xml": strToU8(`<sst xmlns="${MAIN}"><si>${rich}</si></sst>`) },+ ));+ assert.deepEqual(sheet?.rows[0]?.map((cell) => cell?.text), ["_x000D_\nend", "_x000D_\nend"]);+});+test("xlsx: lowercase cell references land in their columns", () => {const [sheet] = readXlsx(workbook(`<worksheet xmlns="${MAIN}"><sheetData><row r="1"><c r="a1"><v>1</v></c><c r="c1"><v>3</v></c></row></sheetData></worksheet>`),