[PR #446] [MERGED] fix: Pages API body parser for invalid JSON and repeated form keys #576

Closed
opened 2026-05-06 13:08:51 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/446
Author: @JaredStowell
Created: 3/11/2026
Status: Merged
Merged: 3/11/2026
Merged by: @james-elicx

Base: mainHead: jstowell/fix-pages-api-body-parser-parity


📝 Commits (6)

  • 8d8ceba Fix Pages API parsing parity
  • 4142041 Fix Pages API body parsing parity
  • af293f9 Fix empty form body parity
  • 3664c89 Merge main into jstowell/fix-pages-api-body-parser-parity
  • b7d7c5f Regenerate entry-templates snapshots after merge
  • a7852c6 fix: propagate statusText through prod server sendCompressed non-compressed path

📊 Changes

8 files changed (+397 additions, -54 deletions)

View changed files

📝 packages/vinext/src/entries/pages-server-entry.ts (+21 -6)
📝 packages/vinext/src/server/api-handler.ts (+19 -4)
📝 packages/vinext/src/server/prod-server.ts (+36 -7)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+27 -10)
📝 tests/api-handler.test.ts (+57 -6)
📝 tests/fixtures/pages-basic/middleware.ts (+1 -1)
tests/fixtures/pages-basic/pages/api/parse.ts (+5 -0)
📝 tests/pages-router.test.ts (+231 -20)

📄 Description

Bring Pages API body parsing in line with Next.js for JSON and urlencoded requests.

Changes

  • return 400 Invalid JSON for malformed application/json requests instead of passing raw strings to handlers
  • preserve duplicate application/x-www-form-urlencoded keys as arrays via querystring.decode()
  • treat empty JSON bodies as {} to match Next.js behavior
  • recognize application/ld+json as JSON
  • avoid logging/reporting invalid JSON as a server error
  • preserve response statusText through the Pages production server path
  • add dev and production regression coverage for all of the above

Testing

  • pnpm test tests/api-handler.test.ts tests/pages-router.test.ts tests/entry-templates.test.ts -u
  • pnpm test tests/features.test.ts -t "production server compression"
  • pnpm run fmt
  • pnpm run typecheck

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/446 **Author:** [@JaredStowell](https://github.com/JaredStowell) **Created:** 3/11/2026 **Status:** ✅ Merged **Merged:** 3/11/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `jstowell/fix-pages-api-body-parser-parity` --- ### 📝 Commits (6) - [`8d8ceba`](https://github.com/cloudflare/vinext/commit/8d8ceba9cfa7f518450fd4e7b9bedb7694f78894) Fix Pages API parsing parity - [`4142041`](https://github.com/cloudflare/vinext/commit/414204151b5f287af036f6c2b74340030180f4e1) Fix Pages API body parsing parity - [`af293f9`](https://github.com/cloudflare/vinext/commit/af293f991580c48950494b580174e2f0fa630828) Fix empty form body parity - [`3664c89`](https://github.com/cloudflare/vinext/commit/3664c89216ee2b1bb36e53e5bee9ef01625a5c88) Merge main into jstowell/fix-pages-api-body-parser-parity - [`b7d7c5f`](https://github.com/cloudflare/vinext/commit/b7d7c5fa51011407ac107afa953e6f66eec5072d) Regenerate entry-templates snapshots after merge - [`a7852c6`](https://github.com/cloudflare/vinext/commit/a7852c6e2ca361d8cf1fbd1454ab7491e01a52d9) fix: propagate statusText through prod server sendCompressed non-compressed path ### 📊 Changes **8 files changed** (+397 additions, -54 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+21 -6) 📝 `packages/vinext/src/server/api-handler.ts` (+19 -4) 📝 `packages/vinext/src/server/prod-server.ts` (+36 -7) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+27 -10) 📝 `tests/api-handler.test.ts` (+57 -6) 📝 `tests/fixtures/pages-basic/middleware.ts` (+1 -1) ➕ `tests/fixtures/pages-basic/pages/api/parse.ts` (+5 -0) 📝 `tests/pages-router.test.ts` (+231 -20) </details> ### 📄 Description Bring Pages API body parsing in line with Next.js for JSON and urlencoded requests. ## Changes - return `400 Invalid JSON` for malformed `application/json` requests instead of passing raw strings to handlers - preserve duplicate `application/x-www-form-urlencoded` keys as arrays via `querystring.decode()` - treat empty JSON bodies as `{}` to match Next.js behavior - recognize `application/ld+json` as JSON - avoid logging/reporting invalid JSON as a server error - preserve response `statusText` through the Pages production server path - add dev and production regression coverage for all of the above ## Testing - `pnpm test tests/api-handler.test.ts tests/pages-router.test.ts tests/entry-templates.test.ts -u` - `pnpm test tests/features.test.ts -t "production server compression"` - `pnpm run fmt` - `pnpm run typecheck` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:51 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#576
No description provided.