Fixes#13533
This fixes regressions in form handling where empty strings in form
fields were incorrectly treated as values instead of using default
values for optional fields.
## Problem
When form fields with Optional types and None defaults received empty
strings (""), FastAPI incorrectly treated them as empty string values
instead of using the default value (None). This affected both:
- x-www-form-urlencoded forms
- multipart/form-data forms
This regression broke existing applications when upgrading from
v0.112.4 to v0.115.x.
## Solution
Modified the _extract_form_body function in fastapi/dependencies/utils.py:
1. Track defined body_field aliases to distinguish between declared
fields and extra fields
2. Don't add empty strings for Form fields since _get_multidict_value
already handles them correctly by returning default values
3. Only add extra fields from received_body that are not already
defined as body_fields to prevent overwriting correctly processed
default values
## Tests
- Added comprehensive regression tests in
tests/test_forms_empty_string_default_13533.py
- All existing form-related tests pass (verified 20+ tests)
- Python 3.8+ compatible (uses typing_extensions.Annotated)