ReviewOS

zig-utils/zig-js

Response: canonicalize status text and redirect URL StringData

#683
Closed chris opened this 9 days ago ·
9 days ago

Parent: #473 Related: #666, #681, #682

Problem

Three Response boundaries still consume physical bytes from toStringV:

  • new Response(..., { statusText }) before persistent response storage;
  • Response.json(..., { statusText }) before persistent response storage;
  • Response.redirect(url) before the owned URL parser.

With physical flat Latin-1 storage active, valid Latin-1 status text can be republished as invalid canonical StringData, while non-ASCII redirect paths can be parsed and percent-encoded from malformed bytes.

Scope

  • Route these three Response coercions through the representation-aware WTF-8 helper.
  • Preserve status-before-statusText-before-headers ordering, exactly one coercion, status validation, null-body status checks, JSON body/content-type behavior, redirect status validation, URL serialization, exception identity, ASCII borrowing, storage ownership, and OOM propagation.
  • Cover constructor/JSON statusText and redirect URL serialization under canonical and physical flat-Latin-1 storage.

No-workaround rules

  • No flat-storage disablement, eager global canonicalization, replacement characters, duplicate coercion, alternate URL/fetch implementation, hidden retry, or fake corpus coverage.
  • No stack, queue, job, Promise, Worker, agent, or Map/Set iterator changes.

Acceptance

  • Response status text is stored as canonical semantic WTF-8.
  • Response.redirect parses canonical semantic URL text and emits exact UTF-8 percent escapes.
  • Each custom ToString hook runs exactly once with existing observable ordering.
  • The witness passes with canonical storage and with flat_storage_active enabled, then the switch is restored and not landed.
  • Focused Debug/ReleaseSafe/TSan and full units pass with exact inventory reported; zero Test262 Web API coverage is stated explicitly.
9 days ago

Implemented and pushed in https://github.com/zig-utils/zig-js/commit/58c054450a23ceda93d977d7363e8be1de5dded7.

Response constructor and Response.json statusText coercions now produce canonical WTF-8 before persistent storage, and Response.redirect canonicalizes its URL input before parsing. The regression witness checks single coercion, exact round-trip status text, and exact UTF-8 percent encoding under both canonical and forced-flat physical storage.

Validation: focused Debug, flat-storage, ReleaseSafe, and TSan 1/1 each; full units 1776 passed, 1 skipped, 0 failed, 0 leaked. Test262 contains 0 Response Web API files, so no corpus conformance claim is made.

9 days ago

Follow-up #700 closed the clone-only statusText edge outside this issue’s construction/JSON/redirect scope. 904c5d6b proves the exact old Response.clone read trips the StringCell canonical-input validator under forced-flat storage; the repaired path passes Debug/ReleaseSafe/TSan and full units.

Sign in to comment on this issue.