Skip to content

fix: resolve validation and parsing bugs in core utilities - #17538

Open
Prabhdeep1701 wants to merge 1 commit into
payloadcms:mainfrom
Prabhdeep1701:fix/payload-validation-and-parsing-bugs
Open

fix: resolve validation and parsing bugs in core utilities#17538
Prabhdeep1701 wants to merge 1 commit into
payloadcms:mainfrom
Prabhdeep1701:fix/payload-validation-and-parsing-bugs

Conversation

@Prabhdeep1701

Copy link
Copy Markdown

What?

Fixed 7 bugs across payload core utilities:

  • addDataAndFileToRequest.tsJSON.parse on _payload field had no try/catch, throwing unhandled SyntaxError on invalid JSON
  • validations.ts — point field validator had swapped lng/lat NaN checks (value[1] checked against lng, value[0] against lat)
  • validations.ts — removed dead typeof lng !== 'number' branch in point validator (always false since parseFloat returns number)
  • validations.ts — upload/relationship error messages appended a numeric index to each invalid value due to swapped .map() parameter names
  • afterRead/promise.tsgetBlockSelect() called with block! before the if (block) guard, risking runtime error on undefined block
  • parseParams/index.tskey in params throws TypeError when params is null/undefined (documented as "current implementation bug" in tests)
  • mergeListSearchAndWhere.tselse if and else branches in hoistQueryParamsToAnd executed identical code

Why?

These are runtime correctness bugs. The swapped lng/lat check causes valid point inputs to be rejected. The unguarded JSON.parse crashes the server on malformed multipart payloads. The non-null assertion can throw on documents with unknown block types.

How?

  • Wrapped _payload JSON.parse in try/catch matching the pattern used for fields.file on the next line
  • Swapped value[0]/value[1] indices to match their correct coordinate variables
  • Moved getBlockSelect() inside the existing if (block) guard
  • Added early return in parseParams for null/undefined, updated tests from "throws TypeError" to "returns {}"
  • Simplified .map() callback to remove misleading index
  • Collapsed duplicate else branches

@Prabhdeep1701 Prabhdeep1701 changed the title fix(payload): resolve validation and parsing bugs in core utilities fix: resolve validation and parsing bugs in core utilities Jul 29, 2026
@Prabhdeep1701

Copy link
Copy Markdown
Author

Hey, this PR fixes 7 bugs found through code review — validation edge cases, an unguarded JSON.parse, and a few code quality issues. Let me know if any changes are needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant