Skip to content

fix(i18n): an image URL that fails must not report it in Chinese - #220

Merged
chaxus merged 1 commit into
mainfrom
fix/bad-image-url-locale
Sep 12, 2026
Merged

chaxus merged 1 commit into
mainfrom
fix/bad-image-url-locale

Conversation

@chaxus

@chaxus chaxus commented Sep 12, 2026

Copy link
Copy Markdown
Member

What users saw

Insert a picture by URL, have the fetch fail (404, or a host that sends no CORS headers), and the editor reports:

无法加载图片:地址无效或目标站不允许跨域访问(可通过 editorConfig.imageProxy 配置图片代理)

In all seven site languages. And it advises configuring editorConfig.imageProxy — not a knob our users can reach, and one we deliberately do not set (it would route their image URLs through a third party).

Found while reading the vendor for #219.

Why

errorBadImageUrl is an ordinary vendor locale key; all 45 locale files translate it (en: "Image URL is incorrect", ja: 画像のURLが正しくありません, ko: 이미지 URL이 잘못되었습니다.). The usual l10n idiom folds those onto <NS>.Controllers.Main.prototype, and the editor reads this.errorBadImageUrl on Asc.c_oAscError.ID.UplImageUrl.

The offline build's Offline controller — the same patch that supplies the in-process server responder — overwrites it on the instance inside loadDocument, shadowing the translated prototype value. documenteditor / spreadsheeteditor / presentationeditor all carry it (plus their ie/ twins); pdfeditor does not.

Fix

Not to translate the sentence — the vendor already translated the original into more languages than we ship. Guard 13 captures the locale value and puts an accessor on the prototype whose setter swallows exactly that one literal:

set(value) { if (value !== OFFLINE_BAD_IMAGE_URL) this.__ooBadImageUrl = value; }

Every other write goes through, so a vendor upgrade that reworded the message legitimately still wins. If loadDocument already ran, the instance's own copy is deleted. If the locale fetch has not resolved yet, the guard reports "not yet" and the guard timer re-applies — it can never leave the property emptier than it found it.

Deliberately not done: setting editorConfig.imageProxy. It would make cross-origin image insertion work — by sending the URL, and the user's interest in it, to whoever runs the proxy. Product decision, not a bug fix.

Tests

  • test/e2e/bad-image-url-locale.spec.ts — opens a real docx and a real xlsx, reads the property the error handler reads off the live controller.
  • test/unit/vendor-bad-image-url.test.ts — pins the vendor side: the three apps still assign exactly the literal the guard matches, and the translated original is still present in en.json and every language the site ships.

Reverse validation (convention 5): with installBadImageUrlGuard commented out, both E2E cases fail with Expected: not "无法加载图片…".

🤖 Generated with Claude Code

https://claude.ai/code/session_01MKNHFQ1kek1cHeqhbH37Pk

errorBadImageUrl is an ordinary vendor locale key -- all 45 locale files
carry a translation, and the editor reads it when the engine raises
UplImageUrl, which is what an inserted image URL that 404s or fails CORS
produces. The offline build's Offline controller then overwrites it on
the controller instance inside loadDocument with a hardcoded Chinese
sentence, so every user of this site saw Chinese there in all seven
languages -- and the sentence advises configuring editorConfig.imageProxy,
which our users cannot reach and which we deliberately do not set.

Guard 13 captures whatever the locale merge left on the prototype and
replaces the property with an accessor whose setter swallows exactly that
literal; every other write goes through, so a vendor upgrade that
reworded the message legitimately still wins. If loadDocument already
ran, the instance's own copy is deleted so reads fall through. If the
locale fetch has not resolved the guard reports "not yet" rather than
pinning an empty string.

Reverse-validated: with the guard commented out of iframe-guards.ts both
E2E cases fail on the Chinese literal.

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 05:40
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying document with  Cloudflare Pages  Cloudflare Pages

Latest commit: afec023
Status: ✅  Deploy successful!
Preview URL: https://30f09892.document-7hm.pages.dev
Branch Preview URL: https://fix-bad-image-url-locale.document-7hm.pages.dev

View logs

@chaxus
chaxus merged commit 7b744ee into main Sep 12, 2026
31 of 33 checks passed
@chaxus
chaxus deleted the fix/bad-image-url-locale branch September 12, 2026 07:58
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