Skip to content

Fix form mapping for file lists and dictionary keys containing brackets - #69782

Open
MohamedHasan3644 wants to merge 7 commits into
dotnet:mainfrom
MohamedHasan3644:fix-69717-form-mapping
Open

MohamedHasan3644 wants to merge 7 commits into
dotnet:mainfrom
MohamedHasan3644:fix-69717-form-mapping

Conversation

@MohamedHasan3644

Copy link
Copy Markdown
Contributor

Description

Bug Description

  • Collection items containing file-list properties could continue binding nonexistent items until the collection-size limit was reached.
  • Root [FromForm] IReadOnlyList<IFormFile> parameters did not respect the parameter name or an explicit [FromForm(Name = "...")] alias.
  • Dictionary keys containing ] were truncated, preventing the submitted values from binding correctly.

Description of Code Changes

  • Report file lists as found only when uploaded files match the current form prefix.
  • Apply equivalent discovery behavior to IReadOnlyList<IFormFile> and IReadOnlyList<IBrowserFile>.
  • Use prefix-matching discovery for IFormFileCollection under indexed paths so unrelated uploads do not keep collection probing active.
  • Preserve the whole-request file collection returned for a bound IFormFileCollection property.
  • Push and pop the form parameter name or alias when mapping a root IReadOnlyList<IFormFile>.
  • Recognize structural closing brackets during dictionary-key discovery instead of truncating keys at the first ].
  • Add regression coverage for the reported scenarios and the reviewer's unrelated-upload case.

Areas Covered

  • File-list discovery and collection termination.
  • Collection items with and without matching attachments.
  • Unrelated uploads with and without matching model fields.
  • Root file-list parameter names and explicit aliases.
  • Exclusion of unnamed uploads from named root file lists.
  • Dictionary keys containing single or multiple embedded closing brackets.
  • Dictionary values containing nested dictionaries, complex objects, and collections.
  • Existing parser boundaries, malformed-key handling, and collection overflow detection.

Validation

Endpoint Regression Tests

  • SupportsFormFileListInCollectionItem

    • Covers a collection item with and without a matching upload.
    • Verifies exactly one line binds, its label is preserved, and the attachment count is correct.
  • SupportsFormFileCollectionInCollectionItem

    • Covers a collection item with and without a matching upload.
    • Verifies exactly one line binds and the whole-request file collection remains available.
  • SupportsRootFormFileList

    • Covers the parameter name files and the explicit alias docs.
    • Verifies both matching files bind and an unnamed upload is excluded.
  • SupportsDictionaryKeyContainingClosingBracket

    • Verifies HTTP 200 and the exact result a=1, x]y=2.

Both rows were verified independently:

  • Without the indexed-prefix discovery fix: both failed with HTTP 400.
  • With the fix restored: both passed with HTTP 200 and the expected binding assertions.

Form-Mapping Unit Tests

  • Deserialize_Dictionary_KeyContainingClosingBracket

    • Covers keys x]y, x], and x]]y.
    • Verifies exact keys and values without mapping errors.
  • Deserialize_Dictionary_KeyContainingClosingBracket_WithNestedDictionary

    • Covers ordinary and bracket-containing keys with nested dictionary values.
  • Deserialize_Dictionary_KeyContainingClosingBracket_WithComplexValue

    • Covers ordinary and bracket-containing keys followed by a property path.
  • Deserialize_Dictionary_KeyContainingClosingBracket_WithCollectionValue

    • Covers ordinary and bracket-containing keys followed by collection indexes.
  • CanDeserialize_ComplexType_IReadOnlyListFormFileWithNoMatches_IsNotFound

    • Verifies an unrelated upload does not mark a named file list as found.
  • TryRead_IBrowserFileList_WithNoMatchingFiles_IsNotFound

    • Verifies conversion succeeds with an empty browser-file list and found = false.

Existing parser expectations were updated for embedded brackets while retaining coverage for structural boundaries and malformed inputs.

Build and Test Results

Recorded local validation:

Validation Result
Focused endpoint regression run 10 passed
Components Endpoints test suite 891 passed, 0 failed, 0 skipped
Http.Extensions test suite 2,302 passed, 0 failed, 0 skipped
Both project builds 0 warnings, 0 errors

Output

Before

69717-without-fix

After

69717-with-fix

Fixes #69717

Copilot AI balanced review requested due to automatic review settings October 13, 2026 04:15
@github-actions github-actions Bot added area-blazor Includes: Blazor, Razor Components area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels Oct 13, 2026
@MohamedHasan3644
MohamedHasan3644 marked this pull request as draft October 13, 2026 04:16
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 13, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @MohamedHasan3644. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation addresses the reported binding failures with consistent behavior and comprehensive regression coverage.

0 open findings

What changed in this PR

Fixes form mapping for file collections and dictionary keys containing closing brackets.

Changes:

  • Corrects prefix-aware file discovery and root file-list binding.
  • Preserves embedded ] characters in dictionary keys.
  • Adds focused unit and endpoint regression coverage.
File Description
RequestDelegateFactoryTests.FormMapping.cs Adds endpoint-level regression tests.
RequestDelegateFactory.cs Applies root file-list parameter prefixes.
BrowserFileFromFormFileTests.cs Tests unmatched browser-file lists.
FormDataMapperTests.cs Covers file discovery and bracketed dictionary keys.
FormDataReader.cs Identifies structural closing brackets.
FileConverter.cs Makes file-list discovery prefix-aware.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Oct 21, 2026
@PureWeen

Copy link
Copy Markdown
Member

/review

@kotlarmilos kotlarmilos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please split the dictionary-key parsing change from the file-list fix. Silently binding the wrong key needs addressing, but we should first define whether embedded  ]  characters are supported or rejected, rather than introducing additional parsing heuristics here.

This branch was previously deployed

1 inactive (outdated) deployment
copilot-pat-pool — 3be3629e Deployed Oct 13, 2026 by dotnet-policy-service[bot] via pat_pool #1801
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Form mapping problems still present in 11.0.0-rc.1: file lists in collection items, root IReadOnlyList<IFormFile>, ']' in dictionary keys

4 participants