GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): GB18030 RTF attachments no longer fail text extraction (… · patroza/t3code@f7d6796

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/provider
    • documentTextWorker.ts
    • userInputAttachments.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/provider/documentTextWorker.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/documentTextWorker.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ const RTF_CODE_PAGES = new Map([
506506
[949, "euc-kr"],
507507
[950, "big5"],
508508
[10000, "macintosh"],
509+
[54936, "gb18030"],
509510
[65001, "utf-8"],
510511
]);
511512

@@ -546,7 +547,8 @@ function* rtf(source: string): Generator<string, void> {
546547
yield String.fromCharCode(byte);
547548
return;
548549
}
549-
encoded ??= new Uint8Array(Math.min(source.length, MAX_OUTPUT * 3 + 4));
550+
// GB18030 spends up to 4 bytes per UTF-16 unit, so a full buffer decodes past MAX_OUTPUT.
551+
encoded ??= new Uint8Array(Math.min(source.length, MAX_OUTPUT * 4 + 4));
550552
if (encodedLength === encoded.length) yield* flushBytes();
551553
encoded[encodedLength++] = byte;
552554
}
Collapse file

‎apps/server/src/provider/userInputAttachments.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/userInputAttachments.test.ts
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ describe("question answer paths", () => {
375375
"{\\rtf1\\ansi\\ansicpg936 \\'c4\n\\'e3\\'ba\\'c3}",
376376
"你好",
377377
],
378+
[
379+
"GB18030 code page",
380+
String.raw`{\rtf1\ansi\ansicpg54936 \'d6\'d0\'ce\'c4 \'95\'32\'82\'36}`,
381+
"中文 𠀀",
382+
],
378383
["Big5 code page", String.raw`{\rtf1\ansi\ansicpg950 \'a7A\'a6n}`, "你好"],
379384
[
380385
"multibyte font charsets and font code pages",
@@ -434,6 +439,27 @@ describe("question answer paths", () => {
434439
}).pipe(Effect.provide(layer)),
435440
);
436441

442+
it.effect("keeps long GB18030 four-byte RTF runs intact up to the output limit", () =>
443+
Effect.gen(function* () {
444+
const config = yield* ServerConfig.ServerConfig;
445+
const path = NodePath.join(config.attachmentsDir, "gb18030-long.rtf");
446+
NodeFS.writeFileSync(
447+
path,
448+
Buffer.concat([
449+
Buffer.from(String.raw`{\rtf1\ansi\ansicpg54936 `, "latin1"),
450+
Buffer.from([0xd6, 0xd0]),
451+
Buffer.alloc(1_050_000 * 4, Buffer.from([0x81, 0x39, 0xee, 0x39])),
452+
Buffer.from("}", "latin1"),
453+
]),
454+
);
455+
const text = yield* Effect.promise(() => extractDocumentText(path, ".rtf"));
456+
expect(text.search(/[^中㐀]/u)).toBe(1_000_000);
457+
expect(text.slice(1_000_000)).toBe(
458+
"\n\n[Extracted text truncated at document extraction limits.]",
459+
);
460+
}).pipe(Effect.provide(layer)),
461+
);
462+
437463
it.effect.each([false, true])("limits the child heap for standalone=%s", (standalone) =>
438464
Effect.acquireUseRelease(
439465
Effect.promise(async () => {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.