8000 Http Client mangles multiple-valued keys in parseMultipartBodyFormat · Issue #55732 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

Http Client mangles multiple-valued keys in parseMultipartBodyFormat #55732

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

Open
tobia opened this issue May 14, 2025 · 1 comment
Open

Http Client mangles multiple-valued keys in parseMultipartBodyFormat #55732

tobia opened this issue May 14, 2025 · 1 comment

Comments

@tobia
Copy link
tobia commented May 14, 2025

Laravel Version

12.x

PHP Version

8.4

Database Driver & Version

No response

Description

Premise: http post data often contains multiple values for the same key. This is needed to post the selection of checkbox widgets, select widgets with the multiple flag set, and others. Laravel's http client receives the post data and stores it internally as a keyed array, therefore the only way to post multiple values for a single key is to associate the key with an array of values:

Http::post('http://example.com/users', [
    'name' => 'Steve',
    'roles' => ['Network Administrator', 'Janitor'],
]);

This bug happens when the request includes both attached files, which forces it to be sent as multipart/form-data, and checkboxes or other input elements with multiple values.
The source of the bug is PendingRequest::parseMultipartBodyFormat in the following code:

is_array($value) ? $value : ['name' => $key, 'contents' => $value]

This fails to handle multiple value arrays, such as ['Network Administrator', 'Janitor'].

Steps To Reproduce

Use the Laravel Http client to make a POST request that includes both an attached file and a multiple-valued key. For example:

Http::attach(
    'attachment', file_get_contents('photo.jpg'), 'photo.jpg', ['Content-Type' => 'image/jpeg']
)->post('http://example.com/users', [
    'name' => 'Steve',
    'roles' => ['Network Administrator', 'Janitor'],
]);

This mangles the multiple-valued key and results in InvalidArgumentException: A 'contents' key is required.

Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0