Skip to content

fix(rules): core/charset is info, not warn, for a late charset meta when the header agrees #1220 - #1222

Merged
nc9 merged 1 commit into
mainfrom
fix/charset-late-meta
Oct 28, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/charset-late-meta

Conversation

@nc9

@nc9 nc9 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Closes #1220

What

core/charset warned "Charset meta is not within the first 1024 bytes" even when the Content-Type header names the same UTF-8 charset. The header decides the decoding before any prescan, so the meta's position is a conformance note there. That case is now info (score-neutral) with the message "The Content-Type header already sets UTF-8; moving the charset meta into the first 1024 bytes is a conformance fix only".

Unchanged: no header charset still warns with the old message; a header that conflicts with the meta still gives the conflict warning wherever the meta sits; a non-UTF-8 page (header and meta both windows-1252) still gets the non-UTF-8 warning; verdictScope stays page. utf8, UTF-8 and a quoted header value count as agreeing.

Tests and docs

  • packages/rules/tests/core-charset.test.ts: the reporter's fixture (a ~7.8 kB inline script before <meta charset>) plus a case per acceptance criterion. Tests that pinned a late meta under an agreeing header as warn now run without a header, so they still exercise the detection and still warn.
  • docs/rules/core/charset.mdx describes the header-agrees case; CHANGELOG [Unreleased] has the entry.
  • scripts/test-suites.ts --run rules, the rules typecheck and make validate in docs/.

Skill: no change needed.

@claude

claude Bot commented Oct 28, 2026

Copy link
Copy Markdown

Reviewed the diff and charset.ts. I found no blocking issues. I didn't run the tests.

  • The new info branch is only reached when declaredCharset is UTF-8 and headerCharset is set. declaredCharset is headerCharset || pageCharset, so the header is itself UTF-8 there. The message "header already sets UTF-8" is therefore accurate. The conflict and non-UTF-8 paths are handled in earlier branches, as the tests show.
  • (nit) docs/rules/core/charset.mdx: the new info bullet is long. Splitting the "still warns" cases into a separate sentence or list would make it easier to read.
  • (nit) The two checks.push objects differ only in status and message. A small ternary would remove the duplication. This is optional, and the explicit branches are fine.
  • (low) I couldn't confirm that info checks on this rule are excluded from the score and the issue list. The docs and PR text say they are, and the existing placement-advice info relies on the same behavior. A test asserting the report's score impact would pin it, but this isn't required.
  • Tests cover the reporter's fixture, label variants, http-equiv, no header, conflict and non-UTF-8. Reverting the fix should make the "no header" tests fail, which looks right.

Overall this looks good to merge.

🤖 Generated with Claude Code

…hen the Content-Type header agrees #1220

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/charset-late-meta branch from a559ca2 to f2712f8 Compare October 28, 2026 13:08
@claude

claude Bot commented Oct 28, 2026

Copy link
Copy Markdown

Review: no blocking issues. The change matches the described behaviour.

  • The new info branch is only reached when declaredCharset is UTF-8 and a conflicting header has already been handled. A non-empty headerCharset there therefore means the header names UTF-8, so the info downgrade is correct.
  • Tests cover the reporter's fixture, the utf8, UTF-8 and quoted header labels, http-equiv, the no-header and conflict cases, the non-UTF-8 case, and the verdictScope pin.

(nit) packages/rules/tests/core-charset.test.ts: the tests were not run with the fix reverted to prove they bite. The "no header still warns" cases do guard the old behaviour. I haven't run them here.
(nit) The CHANGELOG bullet is long. It could be trimmed to the first two sentences.

@nc9
nc9 merged commit a5d1f72 into main Oct 28, 2026
15 checks passed
@nc9
nc9 deleted the fix/charset-late-meta branch October 28, 2026 13:25
nc9 added a commit that referenced this pull request Oct 29, 2026
…er the tags (#1248)

Restores the released v0.0.139 and v0.0.138 CHANGELOG sections byte-for-byte from their tags and puts the bullets of #1215, #1222, #1223 and #1190, deduplicated, under Unreleased. The guard against this is tracked in #1234. Docs: CHANGELOG only. Skill: no change.
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.

core/charset: 1024-byte warning fires although the Content-Type header already declares charset=utf-8

1 participant