Repository navigation
Description
Summary
core/charset warns Charset meta is not within the first 1024 bytes on a page whose HTTP Content-Type header already declares charset=utf-8. The header decides the encoding before the parser looks at any markup, so the position of <meta charset> is irrelevant when the header carries the same charset. The 1024-byte limit only matters for documents with no header charset.
Seen on a Shopify shop (100 URLs): Shopify injects a ~7.8 kB <script data-source-attribution="shopify.exit_interstitial"> right after <head>, so the theme's <meta charset="utf-8"> lands at byte ~7900. The live page answers content-type: text/html; charset=utf-8. The merchant cannot move the injected script.
Related: #659 (placement advice, closed) and #674 (header charset reaching rules, closed). With #674 the header charset now reaches the rule, but the 1024-byte check does not use it.
Reproduce
Tested with v0.0.138 (macOS arm64).
- Save as
index.htmlin an empty dir (the script body is 7,800 filler characters):
<!doctype html>
<html lang="en"><head><script data-source-attribution="shopify.exit_interstitial">/*xxxxxxxx...7800 x...*/</script><meta charset="utf-8"><title>Charset position test page</title><meta name="description" content="A page whose charset meta follows a large inline script."></head><body><h1>Test</h1><p>Hello</p></body></html>- Serve it with a
Content-Type: text/html; charset=utf-8header (python3 -m http.serverguessestext/htmlwithout charset, so use a handler that sets it):
import http.server
class H(http.server.SimpleHTTPRequestHandler):
def guess_type(self, p):
return "text/html; charset=utf-8" if p.endswith(".html") else super().guess_type(p)
http.server.test(H, port=8101, bind="127.0.0.1")curl -sI localhost:8101/index.html shows Content-type: text/html; charset=utf-8.
- Run:
squirrel audit http://localhost:8101/index.html --http --offline --no-publish -f json --rule-include core/charset
Actual
core/charset, check charset, status warn: "Charset meta is not within the first 1024 bytes" (legacyValue: "utf-8").
Expected
No warning (or at most info) when the response header declares charset=utf-8 and the meta charset, wherever it is, agrees. Keep the warning when there is no header charset, and keep the existing conflict warning when header and meta differ.
Versions
v0.0.138.
Triage
Confirmed against packages/rules/src/core/charset.ts. When the meta sits past the 1024-byte prescan window, the rule warns even if the Content-Type header names a charset; a code comment calls it "an HTML-conformance issue even when the header decides the decoding". In practice, a header charset that agrees with the meta means the browser never relies on the prescan, so the page decodes correctly. That makes this advice, not a defect: the same call #659 made for meta placement (info, score-neutral). The conformance note should stay visible, but it shouldn't cost score.
Acceptance Criteria
- A page served with
Content-Type: text/html; charset=utf-8whose<meta charset="utf-8">sits past byte 1024 (the reporter's fixture) reportscore/charsetcheckcharsetasinfo, notwarn. The message says the header already sets UTF-8 and that moving the meta into the first 1024 bytes is a conformance fix only. - Header labels the decoder treats as the same charset as the meta (for example
UTF-8vsutf8) count as agreeing. - The same page with no charset in the header (bare
text/html) still warns "Charset meta is not within the first 1024 bytes". - A header charset that conflicts with the meta still gives the existing "Conflicting charset declarations" warning, whatever the meta's position.
- A non-UTF-8 page (for example header and meta both
windows-1252) still gives the existing non-UTF-8 warning; this change doesn't make it pass. -
verdictScopestayspage(the header is per response). - Tests for each case above in
packages/rules/tests/core-charset.test.ts. The existing tests pass, apart from any that pinned the header-agrees case aswarn, which are updated. -
docs/rules/core/charset.mdxdescribes the header-agrees case;make validatepasses indocs/. -
scripts/test-suites.ts --run rulespasses, including the template-invariance fixtures.
Activity
nc9 commentedon Oct 28, 2026
Thanks @deniskern, confirmed. When the
Content-Typeheader already names a charset and the meta agrees, the 1024-byte position no longer changes how the page decodes, so it shouldn't cost score. We'll report it as info (a conformance note) in that case and keep the warning when the header has no charset or the two disagree. Acceptance criteria are in the issue body, and a fix is in progress.fix(rules): core/charset is info, not warn, for a late charset meta w…
fix(rules): core/charset is info, not warn, for a late charset meta w…