Skip to content

fix(editor): the x2t proxy must not fetch a document as if it were a URL - #231

Merged
chaxus merged 1 commit into
mainfrom
fix/x2t-proxy-string-input
Sep 12, 2026
Merged

chaxus merged 1 commit into
mainfrom
fix/x2t-proxy-string-input

Conversation

@chaxus

@chaxus chaxus commented Sep 12, 2026

Copy link
Copy Markdown
Member

Found while reviewing today's changes.

Guard 14 (#224) turns whatever the vendor passes into bytes before sending it to the x2t worker. For strings it fetched unconditionally. x2t_helper's own handleFileData does not — it sorts strings into DataURL / BlobURL / FileURL / HttpURL / URL and String, and that last case is not an error:

case 'String':
  resolve(new TextEncoder().encode(data));

So a document handed over as text — the empty-document template the offline patch uses (DOCY;v5;7372;…), or the latin1 DOCY form #113 was about — would have been requested as a relative URL instead of converted.

Fix

Strings that are not locations cross untouched, and the worker's own handleFileData decides, exactly as it did before conversion moved out of the frame. Same rule for media entries.

looksLikeUrl is exported for the unit test on purpose: it mirrors a classifier in vendor code that this proxy has to agree with, and getting it wrong turns a document into a request — pinning it directly is cheaper than reaching it through a conversion.

Re-ran the conversion-heavy specs (multi-sheet xlsx, CSV round trip, GBK CSV, PDF annotate + save, CJK PDF export, the offline seam): all green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MKNHFQ1kek1cHeqhbH37Pk

Found reviewing today's changes. Guard 14 turns whatever the vendor
passes into bytes before sending it to the worker, and for strings it
fetched unconditionally. x2t_helper's own handleFileData does not: it
sorts strings into DataURL / BlobURL / FileURL / HttpURL / URL *and*
String, and that last case is not an error -- it encodes the text as
UTF-8 bytes.

So a document handed over as text -- the empty-document template the
offline patch uses, or the latin1 DOCY form of #113 -- would have been
requested as a relative URL instead of converted.

Strings that are not locations now cross untouched, and the worker's own
handleFileData decides, exactly as it did before conversion moved out of
the frame. Same rule for media entries.

looksLikeUrl is exported for the unit test on purpose: it mirrors a
classifier in vendor code that this proxy has to agree with, and getting
it wrong turns a document into a request.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MKNHFQ1kek1cHeqhbH37Pk
@chaxus
chaxus enabled auto-merge (rebase) September 12, 2026 12:36
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying document with  Cloudflare Pages  Cloudflare Pages

Latest commit: 20b4711
Status: ✅  Deploy successful!
Preview URL: https://73b563f4.document-7hm.pages.dev
Branch Preview URL: https://fix-x2t-proxy-string-input.document-7hm.pages.dev

View logs

@chaxus
chaxus merged commit 6a9c198 into main Sep 12, 2026
18 checks passed
@chaxus
chaxus deleted the fix/x2t-proxy-string-input branch September 12, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant