Skip to content

symfony/psr-http-message-bridge v2.3.1 loses the transformations of ConvertEmptyStringsToNull middleware #48626

Closed
@tspencer244

Description

@tspencer244

Laravel Version

10.26.2

PHP Version

8.1.24

Database Driver & Version

No response

Description

Recreating JSON request bodies was changed in v2.3.1 of symfony/psr-http-message-bridge.

symfony/psr-http-message-bridge@ef03b6d

The JSON request body is read using $symfonyRequest->getContent() instead of $symfonyRequest->getPayload()->all() in v2.3.0, and $symfonyRequest->request->all() in v2.2.0.

Because of this, the modifications made to a Laravel request object by the ConvertEmptyStringsToNull middleware gets lost, i.e. empty string values for JSON request keys are not converted to null, and remain as empty strings.

This only affects controller methods that have $request type hinted as Psr\Http\Message\ServerRequestInterface.

Steps To Reproduce

composer create-project laravel/laravel=^10.0 example-app && cd example-app
composer require laravel/framework=10.26.2
{
    echo "<?php"
    echo
    echo "namespace Tests\Feature;"
    echo
    echo "use Tests\TestCase;"
    echo
    echo "class ExampleTest extends TestCase"
    echo "{"
    echo "    public function test_the_application_returns_a_successful_response(): void"
    echo "    {"
    echo "        \$this->postJson('/', ['string' => ''])->assertExactJson(['string' => null]);"
    echo "    }"
    echo "}"
} | tee tests/Feature/ExampleTest.php

Tests should fail:

php artisan test

If we install the previous version:

composer require symfony/psr-http-message-bridge=2.3.0

We should see the tests pass:

php artisan test

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions