Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #54 from qandidate-labs/fix-bc-break
Browse files Browse the repository at this point in the history
Fix bc break
  • Loading branch information
wjzijderveld authored Jan 17, 2022
2 parents c835838 + 814d06b commit 3306f4a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/JsonRequestTransformerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 22 additions & 0 deletions test/JsonRequestTransformerListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3306f4a

Please sign in to comment.