You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//data (JSON)<JSONField>{name: 'data',type: 'json',jsonSchema: {uri: 'a://b/foo.json',//dummyfileMatch: ['a://b/foo.json'],//dummyschema: {//see https://ajv.js.org/strict-mode.html#strict-types//Note: cannot use a string here, have to use an object (see https://github.com/payloadcms/payload/blob/afcc970e3609c1bb6f2d59c4cbbb36ac62730ec9/packages/payload/src/fields/hooks/beforeChange/promise.ts#L137)//see https://github.com/payloadcms/payload/issues/10542//Note: we better use an object here, can still add more values in futuretype: 'object',properties: {value: {anyOf: [{type: 'string'},{type: 'number'},{type: 'boolean'}]}},additionalProperties: false}},
Describe the Bug
The following code always parses strings as JSON without checking the schema:
payload/packages/payload/src/fields/hooks/beforeChange/promise.ts
Line 139 in afcc970
If the following schema is being used, the JSON.parse() call fails but the value is valid:
Best solution is to check if the string value passes the schema before checking jsonError:
payload/packages/payload/src/fields/validations.ts
Line 344 in 6b051bd
Link to the code that reproduces this issue
https://github.com/cbratschi/payload
Reproduction Steps
Binaries:
Node: 22.12.0
npm: 10.9.0
Yarn: 1.22.22
pnpm: N/A
Relevant Packages:
payload: 3.13.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:23 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6031
Available memory (MB): 65536
Available CPU cores: 16
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
The text was updated successfully, but these errors were encountered: