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

Commit 3306f4a

Browse files
authored
Merge pull request #54 from qandidate-labs/fix-bc-break
Fix bc break
2 parents c835838 + 814d06b commit 3306f4a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/JsonRequestTransformerListener.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ private function transformJsonBody(Request $request): bool
5151
{
5252
$data = json_decode((string) $request->getContent(), true);
5353

54-
if (JSON_ERROR_NONE !== json_last_error() || !is_array($data)) {
54+
if (JSON_ERROR_NONE !== json_last_error()) {
55+
return false;
56+
}
57+
58+
if (is_null($data) || is_bool($data)) {
59+
return true;
60+
}
61+
62+
if (!is_array($data)) {
5563
return false;
5664
}
5765

test/JsonRequestTransformerListenerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ public function notJsonContentTypes()
104104
];
105105
}
106106

107+
/**
108+
* @test
109+
* @dataProvider provideValidNonStructuredJson
110+
*/
111+
public function it_also_accepts_valid_json_if_its_not_structured_content($body): void
112+
{
113+
$request = $this->createRequest('application/json', $body);
114+
$event = $this->createGetResponseEventMock($request);
115+
116+
$this->listener->onKernelRequest($event);
117+
$this->assertNull($event->getResponse());
118+
}
119+
120+
public static function provideValidNonStructuredJson()
121+
{
122+
return [
123+
'boolean true' => ['true'],
124+
'boolean false' => ['false'],
125+
'null' => ['null'],
126+
];
127+
}
128+
107129
private function createRequest($contentType, $body)
108130
{
109131
$request = new Request([], [], [], [], [], [], $body);

0 commit comments

Comments
 (0)