Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions packages/payload/src/fields/hooks/afterRead/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,14 @@ export const promise = async ({
(curBlock) => typeof curBlock !== 'string' && curBlock.slug === blockTypeToMatch,
) as Block | undefined)

const { blockSelect, blockSelectMode } = getBlockSelect({
block: block!,
// TODO: fix this
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
select: select?.[field.name]!,
selectMode: selectMode!,
})

if (block) {
const { blockSelect, blockSelectMode } = getBlockSelect({
block,
// TODO: fix this
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
select: select?.[field.name]!,
selectMode: selectMode!,
})
traverseFields({
blockData: row,
collection,
Expand Down
15 changes: 4 additions & 11 deletions packages/payload/src/fields/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,7 @@ export const upload: UploadFieldValidation = async (value, options) => {

if (invalidRelationships.length > 0) {
return `This relationship field has the following invalid relationships: ${invalidRelationships
.map((err, invalid) => {
return `${err} ${JSON.stringify(invalid)}`
})
.map((value) => JSON.stringify(value))
.join(', ')}`
}
}
Expand Down Expand Up @@ -950,9 +948,7 @@ export const relationship: RelationshipFieldValidation = async (value, options)

if (invalidRelationships.length > 0) {
return `This relationship field has the following invalid relationships: ${invalidRelationships
.map((err, invalid) => {
return `${err} ${JSON.stringify(invalid)}`
})
.map((value) => JSON.stringify(value))
.join(', ')}`
}
}
Expand Down Expand Up @@ -1075,15 +1071,12 @@ export const point: PointFieldValidation = (value = ['', ''], { req: { t }, requ
const lat = parseFloat(String(value[1]))
if (
required &&
((value[0] && value[1] && typeof lng !== 'number' && typeof lat !== 'number') ||
Number.isNaN(lng) ||
Number.isNaN(lat) ||
(Array.isArray(value) && value.length !== 2))
(Number.isNaN(lng) || Number.isNaN(lat) || (Array.isArray(value) && value.length !== 2))
) {
return t('validation:requiresTwoNumbers')
}

if ((value[1] && Number.isNaN(lng)) || (value[0] && Number.isNaN(lat))) {
if ((value[0] && Number.isNaN(lng)) || (value[1] && Number.isNaN(lat))) {
return t('validation:invalidInput')
}

Expand Down
6 changes: 5 additions & 1 deletion packages/payload/src/utilities/addDataAndFileToRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export const addDataAndFileToRequest: AddDataAndFileToRequest = async (req) => {
}

if (fields?._payload && typeof fields._payload === 'string') {
req.data = JSON.parse(fields._payload)
try {
req.data = JSON.parse(fields._payload)
} catch {
throw new APIError('Invalid JSON in _payload field', 400)
}
}

if (!req.file && fields?.file && typeof fields?.file === 'string') {
Expand Down
4 changes: 0 additions & 4 deletions packages/payload/src/utilities/mergeListSearchAndWhere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ export const hoistQueryParamsToAnd = (currentWhere: Where, incomingWhere: Where)

if ('and' in currentWhere && currentWhere.and) {
currentWhere.and.push(incomingWhere)
} else if ('or' in currentWhere) {
currentWhere = {
and: [currentWhere, incomingWhere],
}
} else {
currentWhere = {
and: [currentWhere, incomingWhere],
Expand Down
14 changes: 6 additions & 8 deletions packages/payload/src/utilities/parseParams/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,14 @@ describe('parseParams', () => {
expect(result).toEqual({})
})

it('should throw error for null params (current implementation bug)', () => {
expect(() => {
parseParams(null as any)
}).toThrow(TypeError)
it('should return empty object for null params', () => {
const result = parseParams(null as any)
expect(result).toEqual({})
})

it('should throw error for undefined params (current implementation bug)', () => {
expect(() => {
parseParams(undefined as any)
}).toThrow(TypeError)
it('should return empty object for undefined params', () => {
const result = parseParams(undefined as any)
expect(result).toEqual({})
})

it('should preserve unknown parameters', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/payload/src/utilities/parseParams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ export const numberParams = ['depth', 'limit', 'page']
* c. `sort` provided as a comma-separated string or array is converted to an array of strings
*/
export const parseParams = (params: RawParams): ParsedParams => {
const parsedParams = (params || {}) as ParsedParams
if (!params || typeof params !== 'object') {
return {} as ParsedParams
}

const parsedParams = params as ParsedParams

// iterate through known params to make this very fast
for (const key of booleanParams) {
Expand Down
Loading