Skip to content

Multipart array index and data loss in HTTP client #59992

@RomainMazB

Description

@RomainMazB

Laravel Version

13.7.0

PHP Version

8.4.1

Database Driver & Version

No response

Description

Passing nested array as multipart in the HTTP client results in an index loss.
This array:

Http::asMultipart()->post('http://foo.com/multipart', [
  'user' => [
    'name' => 'foo',
    'email' => 'bar@baz.com'
  ]
]);

results to this wrong body (the name and email index are lost)

--c88de6383a5ee47d40326eed35ccdff493bbb202
Content-Disposition: form-data; name="user[]"
Content-Length: 3

foo
--c88de6383a5ee47d40326eed35ccdff493bbb202
Content-Disposition: form-data; name="user[]"
Content-Length: 11

bar@baz.com
--c88de6383a5ee47d40326eed35ccdff493bbb202--

Also, when using two arrays containing the same index, only the second one is added to the data (in addition to the name index loss):

Http::asMultipart()->post('http://foo.com/multipart', [
  'user' => [
    'name' => 'foo',
  ],
  'admin' => [
    'name' => 'bar',
  ]
]);

results to this multipart body (the whole user entry data is lost):

-3832af0fa930d17bf9d26df6d6c948ec91c74edb
Content-Disposition: form-data; name="admin[]"
Content-Length: 3

bar
--3832af0fa930d17bf9d26df6d6c948ec91c74edb--

Steps To Reproduce

I created a repository with a branch containing two tests to demonstrate the issues.
The tests can be read here: RomainMazB@0029219

Way to fix

This PR: #59984 exists to upgrade guzzle/psr7 to ^2.9 and remove the HTTP Client implementation which causes the issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions