Closed
Description
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