fix(rest): parse where param in parseParams#15745
fix(rest): parse where param in parseParams#15745hugomeduarte wants to merge 1 commit intopayloadcms:mainfrom
Conversation
|
Pull Request titles must follow the Conventional Commits specification and have valid scopes. Unknown scope "rest" found in pull request title "fix(rest): parse where param in parseParams". Scope must match one of: cpa, claude, db-*, db-d1-sqlite, db-mongodb, db-postgres, db-vercel-postgres, db-sqlite, db-d1-sqlite, drizzle, email-*, email-nodemailer, email-resend, eslint, graphql, kv, kv-redis, live-preview, live-preview-react, live-preview-vue, next, payload-cloud, plugin-cloud, plugin-cloud-storage, plugin-ecommerce, plugin-form-builder, plugin-import-export, plugin-mcp, plugin-multi-tenant, plugin-nested-docs, plugin-redirects, plugin-search, plugin-sentry, plugin-seo, plugin-stripe, richtext-*, richtext-lexical, richtext-slate, sdk, storage-*, storage-azure, storage-gcs, storage-r2, storage-uploadthing, storage-vercel-blob, storage-s3, translations, ui, templates, examples(/(\w|-)+)?, deps. |
What?
Parse the
wherequery parameter when it is sent as a JSON string in REST API requests (e.g.?where={"read":{"equals":false}}), so that the filter is applied correctly. Whenwhereis already an object (e.g. from bracket notation like the Admin uses), it is left unchanged.Why?
In GET requests, all query parameters are strings. When the client sends
whereas a JSON string,parseParamsdid not parse it, so find (and count, delete, etc.) operations received a string instead of an object and the filter was not applied. The same pattern already exists for thedataparameter; this adds the same forwhere.How?
In
parseParams, after thedatablock: ifwhereis present and is a string, runJSON.parse(params.where)and assign the result toparsedParams.where. Whenwhereis already an object (e.g. from bracket notation), the condition is false and we do nothing, so existing behavior is preserved. Added tests for the string case, the object passthrough case, and invalid JSON (expect throw).