Repository navigation
fix(crawler): carry the Content-Type charset to rules so core/charset sees header declarations #674 - #883
Conversation
7d13281 to
dfc56ad
Compare
|
Reviewed the diff. The change is small and well tested: the header charset is stored beside the media type, stored as JSON so there's no schema migration, and it's re-joined in
Test coverage is good: there are unit tests for the parser, |
|
Review triage (dfc56ad):
The branch needs a rebase over the v0.0.117 release cut; that is next in my queue. |
… sees header declarations #674 New optional ResponseHeaders.contentTypeCharset, parsed quote-aware from the raw header and stored beside the media type; buildHeadersMap rejoins them. An incremental hash-match reuse refreshes it from the fetched response. Old records without the key read as before. Signed-off-by: Nik Cubrilovic <[email protected]>
dfc56ad to
d64473e
Compare
|
Review of #883 (pass the Content-Type charset through to I read the diff and traced both fetch paths: plain HTTP and cloud render. Both build
Test coverage is good: unit tests for the parser, No blocking issues found. |
Closes #674
Closes #659
#659's only open part was the header-declared case, blocked on #674 per its 2026-10-12 release check. Its placement advice, 1024-byte check and conflict warning shipped in pub#676 (
core-charset.test.ts23/23 on main), and this PR's e2e shows the header-only page passing in a real crawl.What changed
ResponseHeaders(core-contracts) gains an optionalcontentTypeCharset.contentTypestays the lowercased media type, so nothing comparing it changes.contentTypeCharset()(crawlerfetcher.ts) reads thecharsetparameter from the raw header: split on;outside quoted strings, quoted value unescaped, only an RFC 9110 token of at most 40 characters counts.Content-Typeinresult.headers.hash_matchreuse) refreshes the charset from the response just fetched, so old records pick it up and a charset-only change is not lost.buildHeadersMaprejoins them astext/html; charset=<label>for rules. A record without the key reads as before: no charset.Real CLI audit (before / after)
Local server:
/sendstext/html; charset=utf-8with no meta,/conflictsendstext/html; charset=iso-8859-1with<meta charset="utf-8">.squirrel audit http://localhost:<port>/ -m 5 --http --offline --disable-discovery-probes --rule-include core/charset -f json, fresh HOME and project dir each run:fail No charset declaration foundon/, nothing on/conflict/passes,warn Conflicting charset declarations: header iso-8859-1, page utf-8on/conflictCloud
The checkpoint stores
headersas a record of unknown values, so cloud audits get this when the gitlink moves. The API'sresponseHeadersSchemastrips unknown keys from published reports; follow-up squirrelscan/repo#2947 (does not affect rule results).Acceptance criteria
core/charsetin a real CLI auditiso-8859-1vs metautf-8reported in a real auditbuild-headers-map.test.ts)charset-header-674-e2e.test.ts(local Bun server -> createCrawler -> SQLite -> v1 and v2 rule engines), plus an incremental hash-match caseTests
packages/audit-engine/tests/charset-header-674-e2e.test.ts(fails on origin/main's crawler; the incremental case fails without the reuse refresh)packages/crawler/tests/content-type-charset-674.test.tspackages/audit-engine/tests/build-headers-map.test.tsTypecheck (crawler, audit-engine, core-contracts), oxlint on changed files, golden suite (209/210; the one failure was a 180 s timeout in
rule-cache-replay-goldenunder load, and that file passes alone, 11/11 in 15 s), codex review (2 rounds; P2 hash-match reuse and P3 quoted parameters fixed).