fix: strictly match decodeRequest content types#81
Conversation
Normalize the request media type before matching supported decodeRequest content types.\n\nThis avoids rejecting valid mixed-case media types and prevents invalid near-match content types from being accepted by substring checks. URL-encoded request bodies are parsed directly with URLSearchParams so decoding does not depend on runtime content-type casing behavior.
Greptile SummaryThis PR fixes
Confidence Score: 5/5Safe to merge — the changes are narrowly scoped to content-type matching and parsing, all three media-type branches are covered by new and existing tests, and the helper function correctly preserves original parameters when normalizing the header. The logic change is straightforward: substring inclusion replaced with strict equality on a lowercased, parameter-stripped media type. The withNormalizedContentType helper correctly rebuilds the header while preserving parameters. Switching application/x-www-form-urlencoded to URLSearchParams is compatible with the decode function's Iterable signature. Regression coverage is thorough, including the previously flagged mixed-case multipart path. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/decode.ts | Normalizes content-type to its bare media type before strict equality checks; adds withNormalizedContentType helper for multipart requests and switches url-encoded parsing to URLSearchParams. |
| test/roundtrip.test.ts | Adds three new test cases: parameterized url-encoded content-type, mixed-case content-type acceptance (including Multipart/Form-Data), and rejection of near-match content-type substrings. |
| .changeset/strict-content-type-decoding.md | New patch changeset entry for the content-type normalization fix. |
Reviews (2): Last reviewed commit: "test: cover mixed-case multipart decode ..." | Re-trigger Greptile
Add regression coverage for mixed-case multipart/form-data content types.\n\nNormalize the multipart content-type passed to the platform formData parser while preserving parameters such as boundary, so decodeRequest handles mixed-case multipart headers consistently.
Summary
content-typeheader to the media type before parameters and compare supported types exactly.application/x-www-form-urlencodedbodies viaURLSearchParamsso mixed-case media types decode consistently across runtimes.Verification
bun fmtbun run lint:fixbun run lintbun testbun run typecheckCloses #68