Skip to content

fix: prevent panic when text value sent to FormFile field#932

Merged
wolveix merged 4 commits intodanielgtaylor:mainfrom
alexisvisco:fix-formfile-text-value-panic
Feb 16, 2026
Merged

fix: prevent panic when text value sent to FormFile field#932
wolveix merged 4 commits intodanielgtaylor:mainfrom
alexisvisco:fix-formfile-text-value-panic

Conversation

@alexisvisco
Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread huma.go Outdated
alexisvisco and others added 3 commits December 29, 2025 10:14
…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.
Revert unnecessary comment change
FormFiles in the body are now correctly required by default, so the "optional" test needed to be explicitly defined
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.93%. Comparing base (c7a8a79) to head (f306169).
⚠️ Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #932      +/-   ##
==========================================
+ Coverage   92.53%   92.93%   +0.40%     
==========================================
  Files          23       23              
  Lines        4472     4644     +172     
==========================================
+ Hits         4138     4316     +178     
+ Misses        275      271       -4     
+ Partials       59       57       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wolveix wolveix merged commit 687b98f into danielgtaylor:main Feb 16, 2026
4 checks passed
@wolveix
Copy link
Copy Markdown
Collaborator

wolveix commented Feb 16, 2026

Awesome, thanks so much!

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

3 participants