diff --git a/src/JsonRequestTransformerListener.php b/src/JsonRequestTransformerListener.php index 0938ec5..ba61360 100755 --- a/src/JsonRequestTransformerListener.php +++ b/src/JsonRequestTransformerListener.php @@ -51,7 +51,15 @@ private function transformJsonBody(Request $request): bool { $data = json_decode((string) $request->getContent(), true); - if (JSON_ERROR_NONE !== json_last_error() || !is_array($data)) { + if (JSON_ERROR_NONE !== json_last_error()) { + return false; + } + + if (is_null($data) || is_bool($data)) { + return true; + } + + if (!is_array($data)) { return false; } diff --git a/test/JsonRequestTransformerListenerTest.php b/test/JsonRequestTransformerListenerTest.php index 83d2125..d09044d 100755 --- a/test/JsonRequestTransformerListenerTest.php +++ b/test/JsonRequestTransformerListenerTest.php @@ -104,6 +104,28 @@ public function notJsonContentTypes() ]; } + /** + * @test + * @dataProvider provideValidNonStructuredJson + */ + public function it_also_accepts_valid_json_if_its_not_structured_content($body): void + { + $request = $this->createRequest('application/json', $body); + $event = $this->createGetResponseEventMock($request); + + $this->listener->onKernelRequest($event); + $this->assertNull($event->getResponse()); + } + + public static function provideValidNonStructuredJson() + { + return [ + 'boolean true' => ['true'], + 'boolean false' => ['false'], + 'null' => ['null'], + ]; + } + private function createRequest($contentType, $body) { $request = new Request([], [], [], [], [], [], $body);