fix(server): serve html assets with utf-8 charset - #6409
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved 9e42ae6 Simple bug fix adding UTF-8 charset header for HTML assets. The change follows the existing pattern for SVG files in the same function and includes test coverage. You can customize Macroscope's approvability policy. Learn more. |
What Changed
The
/api/assetsroute served workspace HTML files with a baretext/htmlcontent type. It now sendstext/html; charset=utf-8for.html/.htmfiles, plus tests for the header.Why
Opening an HTML file in the built-in browser garbles any non-ASCII text unless the file declares its own
<meta charset>(agents often don't). The asset response has no charset and setsX-Content-Type-Options: nosniff, so Chromium falls back to windows-1252 and UTF-8 content renders as mojibake (你好 becomes ä½ å¥½).HTML is the only type that needs this: CSS and module scripts already default to UTF-8, classic scripts inherit the document's encoding, and SVG is XML which is UTF-8 by default.
UI Changes
Same file served without and with the fix:
Before:
After:
Checklist
Note
Low Risk
Narrow header change on the asset route with tests; no auth, data, or routing logic changes.
Overview
Workspace HTML files served from
/api/assetsnow getContent-Type: text/html; charset=utf-8for.htmland.htmpaths (case-insensitive), instead of a baretext/htmlfrom the file response.That aligns asset responses with the built-in browser expectation so UTF-8 text renders correctly when pages lack their own
<meta charset>, especially withX-Content-Type-Options: nosniffalready set on these responses.Tests cover
.html/.htmand uppercase.HTM; SVG sandbox headers and other asset types are unchanged.Reviewed by Cursor Bugbot for commit 9e42ae6. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Serve HTML assets with
Content-Type: text/html; charset=utf-8inassetResponseHeadersUpdates
assetResponseHeadersto setContent-Type: text/html; charset=utf-8for.htmland.htmfiles (case-insensitive). Previously, HTML assets were served without an explicit charset, which could cause encoding issues in browsers.Macroscope summarized 9e42ae6.