fix(plugins): parse query params as input for GET/HEAD/DELETE routes#2163
Open
dchaudhari7177 wants to merge 4 commits into
Open
fix(plugins): parse query params as input for GET/HEAD/DELETE routes#2163dchaudhari7177 wants to merge 4 commits into
dchaudhari7177 wants to merge 4 commits into
Conversation
Plugin route input was always read via request.json(), so a GET, HEAD, or DELETE route with an input schema always failed validation — those methods carry no body, so request.json() resolves to undefined and the Zod check rejects it (emdash-cms#2146). A new parseRouteInput helper switches on method: POST/PUT/PATCH parse the JSON body as before; GET/HEAD/DELETE parse the URL query string into an object (repeated keys become arrays). Applied to both the trusted and sandboxed plugin route dispatch paths. Fixes emdash-cms#2146
🦋 Changeset detectedLatest commit: 9a19297 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
ascorbic
reviewed
Jul 21, 2026
ascorbic
left a comment
Collaborator
There was a problem hiding this comment.
Thanks. Can you update the docs too, because this is new behaviour
Contributor
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
oxlint --deny-warnings flagged values[0]! as an unnecessary type assertion (noUncheckedIndexedAccess is off, so values[0] is already string). Remove it; behaviour is identical.
The route dispatcher now parses bodyless-method input from the query string. Document the parsing semantics (repeated keys become arrays, single keys stay scalars, values are always strings so use z.coerce) and fix the method list to GET/HEAD/DELETE.
Contributor
Author
|
Added docs for the new behaviour in
Let me know if you'd like it anywhere else. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
A plugin route with an
inputschema always failed validation on GET, HEAD, and DELETE. Route input was read exclusively viarequest.json(), and those methods carry no body — sorequest.json()resolves toundefinedand the Zod check rejects every request with a 400.New
parseRouteInput(request)helper switches on method:?tag=a&tag=b) becomes an array, a single key stays a scalar; no params yields{}so all-optional/defaulted schemas still validateApplied at both plugin dispatch sites in
emdash-runtime.ts(trusted/configured plugins and the sandboxed path), replacing the duplicatedtry { request.json() }blocks.The exact repro from the issue now works:
Closes #2146
Type of change
Checklist
pnpm typecheckpasses for my change (packages/core— the one remaining error,cacheControlonManifestRouteEntryinbundle-utils.ts, is pre-existing and reproduces on a cleanmain)pnpm lintpasses for the changed files (overallpnpm lintfails on a pre-existing error inpackages/registry-verification)pnpm testpasses (targeted:packages/core tests/unit/plugins/routes.test.ts, 45/45)pnpm formathas been runemdashpatch)AI-generated code disclosure
Tests
New
parseRouteInputsuite inroutes.test.ts: GET/HEAD/DELETE query parsing, repeated-key-to-array, empty-query{}, JSON body for POST/PUT/PATCH,undefinedfor a body method with no body, and an end-to-end GET throughPluginRouteHandler.invokewith az.coerceschema returning{ limit: 20, q: "hello" }.