Repository navigation
Studio: read web pages in the encoding the page itself declares - #11598
Conversation
Review + Studio UI evidencePinned head: I tested the real Studio chat flow in Chromium at 1280×1400, on two isolated installs: merge base
Readable pages: 1 → 3. The control reads the same on both sides. Review fixes pushed after the first commit:
Tests: CI: the one red job, |
|
Confirmed main's web fetch in studio/backend/core/inference/tools.py ignores the page's own meta charset, so pages like kakaku.com arrive garbled. Thanks for the before/after on real pages, will get this reviewed. |
Collapse the BOM, meta, and UTF-8 fallback into one codec so the header-failure path cannot drift from the primary path, and classify HTML versus XML explicitly in the meta prescan. The BOM precedence test now uses a UTF-8 BOM so the contradicting meta is actually visible to the prescan, and an uppercase http-equiv declaration is covered.
The prescan matched <meta anywhere in the head, so markup quoted inside another tag's attribute was taken as the page's declaration, and deleting comments before scanning could splice an attribute value into a valid label. Walk comments and whole tags in one pass, consuming quoted attribute values, as the browser prescan does.
Walking every tag let the tag name and attribute patterns overlap, so a head with many unterminated tags backtracked for tens of seconds, and a tag cut off by the scan window let the walk resume inside its attribute value. Attributes now start only after whitespace or a slash, and an unterminated tag ends the scan as in the browser prescan.
|
Pushed three follow-up commits on top of this branch:
Checked against pages fetched today with no header charset: kakaku.com, itmedia.co.jp (Shift_JIS), inven.co.jp (EUC-JP) and pconline.com.cn (GBK) go from thousands of U+FFFD on main to none. UTF-8 sites are unchanged. |
|
Codex review and CI for head
|
Lyxot
left a comment
There was a problem hiding this comment.
LGTM. Pages that declare their charset only in <meta> or an XML prolog now decode correctly (verified on kakaku.com, itmedia, inven, pconline); the header charset and a BOM still take precedence, and UTF-8 pages are unchanged.
…othai#11598) * Studio: read web pages in the encoding the page itself declares * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: decode meta charset labels the way browsers do * Studio: only sniff meta charset in HTML responses * Studio: sniff headerless bodies only when they look like HTML * Studio: read the XML prolog of headerless XML bodies * Studio: match only a complete meta tag name * refactor(studio): simplify meta charset fallback and tighten its tests Collapse the BOM, meta, and UTF-8 fallback into one codec so the header-failure path cannot drift from the primary path, and classify HTML versus XML explicitly in the meta prescan. The BOM precedence test now uses a UTF-8 BOM so the contradicting meta is actually visible to the prescan, and an uppercase http-equiv declaration is covered. * fix(studio): read meta charset only from real meta tags The prescan matched <meta anywhere in the head, so markup quoted inside another tag's attribute was taken as the page's declaration, and deleting comments before scanning could splice an attribute value into a valid label. Walk comments and whole tags in one pass, consuming quoted attribute values, as the browser prescan does. * fix(studio): end the meta prescan at an unterminated tag Walking every tag let the tag name and attribute patterns overlap, so a head with many unterminated tags backtracked for tens of seconds, and a tag cut off by the scan window let the walk resume inside its attribute value. Attributes now start only after whitespace or a slash, and an unterminated tag ends the scan as in the browser prescan. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lyxot <[email protected]>

When chat reads a page that states its encoding only inside the page, which is common on Japanese and Chinese sites like kakaku.com, Studio assumes UTF-8. The model gets garbled text and says it cannot read the page.
If the server does not name the encoding and the file has no marker, Studio now reads the encoding from the top of the page, the same way browsers do.