这是indexloc提供的服务,不要输入任何密码
Skip to content

Fix panic when sending an empty file field in a form #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

Supet1337
Copy link

Fix panic on empty file field in RawBody

Problem

When an empty file field is submitted in a form (multipart/form-data), form.Value contains an empty string (""), but form.File is missing. This leads to a panic with the error: unsupported param type huma.FormFile

Solution

Now, before accessing form.Value[p.Name], we check if the value is an empty string and handle it correctly. If the parameter is required and not a valid file, a proper validation error is returned instead of causing a panic.

@danielgtaylor danielgtaylor requested a review from Copilot April 22, 2025 04:48
Copy link
Contributor

@Copilot 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 occurs when an empty file field is submitted as part of a multipart form.

  • The change adds a condition that treats an empty string in form.Value[p.Name] as a missing parameter.
  • This prevents accessing a non-existent file when form.File[p.Name] is also missing.

Copy link

codecov bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.10%. Comparing base (58aba1e) to head (9a51c8a).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #785   +/-   ##
=======================================
  Coverage   93.10%   93.10%           
=======================================
  Files          23       23           
  Lines        5296     5296           
=======================================
  Hits         4931     4931           
  Misses        313      313           
  Partials       52       52           

☔ 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.

@danielgtaylor danielgtaylor merged commit a4caf55 into danielgtaylor:main Apr 22, 2025
5 checks passed
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.

2 participants