Skip to content

Cloning request as PSR-7 with body of an array of objects results in duplicated objects #57027

@ineptvagrant

Description

@ineptvagrant

Came across this while trouble shooting why Sentry is reporting a body with duplicated payload objects.

per documentation https://laravel.com/docs/12.x/requests#psr7-requests
composer require nyholm/psr7

If the body is an array of objects, then the new parsed body is an array with duplicated object(s)

curl --header "Content-Type: application/json" \
  --request POST \
  --data '[{"test": "1"}]' \
  https://api.something.com/receive

$newRequest = Container::getInstance()->make(ServerRequestInterface::class);

$newRequest->getParsedBody()
result = {array[2]} 
 0 = {array[1]} 
  test = "1"
 1 = {array[1]} 
  test = "1"

Traced to here

array_merge($request->getParsedBody() ?? [], $illuminateRequest->getPayload()->all())

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions