Correctly handle associative array keys in HTTP client multipart requests#59996
Closed
RomainMazB wants to merge 2 commits intolaravel:13.xfrom
Closed
Correctly handle associative array keys in HTTP client multipart requests#59996RomainMazB wants to merge 2 commits intolaravel:13.xfrom
RomainMazB wants to merge 2 commits intolaravel:13.xfrom
Conversation
… and add corresponding test.
Member
|
Has conflicts. |
Member
|
@RomainMazB Can you resend a new PR with resolved merge conflict |
Contributor
Author
It's unnecessary, now that #59984 was reopened and merged, this issue doesn't exist anymore. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue where associative array keys may be lost when sending nested array values as multipart data through the HTTP client.
For example, the following payload:
should preserve the nested keys and generate multipart field names such as:
Instead, the current Laravel-side multipart expansion may flatten these values using
[], which causes the original array keys to be lost. In some cases, when multiple nested arrays contain the same inner key, this can also result in data being overwritten or dropped.Fixes #59992.
Changes
This PR updates
parseMultipartBodyFormatso that keyed array values are expanded using their associative keys instead of being converted to unkeyed array fields.It also adds a regression test covering the case where two root fields contain the same nested key:
The expected multipart fields are now preserved as:
Note about the preferred fix
While this PR fixes the reported issue within Laravel's current multipart parsing logic, I still believe #59984 would be the better long-term solution.
The reason is that this PR adds more Laravel-side logic around multipart array expansion, even though this behavior is now handled directly by Guzzle's MultipartStream in guzzlehttp/psr7 ^2.9.
In other words, this PR demonstrates that the current Laravel implementation does not fully cover the same behavior as Guzzle. However, instead of continuing to duplicate and maintain multipart array expansion logic inside the framework, it would likely be cleaner and more robust to rely on Guzzle for this responsibility.
So although this PR fixes #59992 directly, I would personally prefer reconsidering #59984, which removes the duplicated framework logic and delegates nested multipart array expansion to the underlying HTTP library.