Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions apps/server/src/provider/documentTextWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,17 @@ function* rtf(source: string): Generator<string, void> {
if (control === "mac" || (control === "ansicpg" && value === 10000))
state.decoder = new TextDecoder("macintosh");
else if (control === "ansicpg") {
// Per-byte decoding only supports single-byte Windows code pages.
if (value !== 874 && (value < 1250 || value > 1258))
throw new Error("Unsupported RTF code page");
state.decoder = new TextDecoder(`windows-${value}`, { fatal: true });
// Per-byte decoding only supports single-byte code pages.
const label =
value === 0
? "windows-1252"
: value === 866
? "ibm866"
: value === 874 || (value >= 1250 && value <= 1258)
? `windows-${value}`
: undefined;
if (!label) throw new Error("Unsupported RTF code page");
state.decoder = new TextDecoder(label, { fatal: true });
} else if (control === "uc") {
if (!Number.isSafeInteger(value) || value < 0)
throw new Error("Invalid RTF fallback count");
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/provider/userInputAttachments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ describe("question answer paths", () => {
String.raw`{\rtf1\mac\ansicpg10000 Caf\'8e Cr\'8fme}`,
"Café Crème",
],
["default ANSI code page", String.raw`{\rtf1\ansi\ansicpg0 Caf\'e9}`, "Café"],
[
"DOS Cyrillic code page",
String.raw`{\rtf1\ansi\ansicpg866 \'8f\'e0\'a8\'a2\'a5\'e2}`,
"Привет",
],
[
"font character set",
String.raw`{\rtf1\ansi\ansicpg1252\deff1{\fonttbl\f0\fnil\fcharset178 GeezaPro;\f1\fnil\fcharset0 LucidaGrande;}
Expand Down
Loading