Skip to content

Conversation

@alexisvisco
Copy link

Skip FormFile and []FormFile fields in formValueParser to prevent panic when multipart form data contains text values for fields expecting file uploads.

Previously, sending a text value to a FormFile field would cause parseInto() to panic with 'unsupported param type huma.FormFile'. Now it properly returns a validation error 'File required'.

Partially fixes #912

Skip FormFile and []FormFile fields in formValueParser to prevent
panic when multipart form data contains text values for fields
expecting file uploads.

Previously, sending a text value to a FormFile field would cause
parseInto() to panic with 'unsupported param type huma.FormFile'.
Now it properly returns a validation error 'File required'.

Partially fixes danielgtaylor#912
Copilot AI review requested due to automatic review settings December 27, 2025 13:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a panic that occurred when multipart form data contains text values (without filename) for fields expecting file uploads. The fix prevents parseInto() from attempting to parse FormFile types by skipping them in the formValueParser, allowing the proper file handling code to return a validation error instead.

  • Skip FormFile and []FormFile fields in formValueParser to prevent panic
  • Add comprehensive test case for text value sent to FormFile field
  • Ensures proper "File required" validation error is returned

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
huma.go Adds early return in formValueParser to skip FormFile and []FormFile fields, preventing panic in parseInto()
huma_test.go Adds test case validating that text values sent to FormFile fields return proper validation error instead of panicking

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…rison

This change improves the type checking for FormFile fields by using
reflect.TypeOf() for direct type comparison instead of string comparison.
This is more reliable and performant.
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.

Got panic when sending a string in file field in a form

1 participant