Skip to content

Commit ddc9da4

Browse files
committed
check if params given to API are really an array
Signed-off-by: Artur Neumann <[email protected]>
1 parent 0d6a706 commit ddc9da4

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lib/private/AppFramework/Http/Request.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,12 @@ protected function decodeContent() {
431431
// 'application/json' must be decoded manually.
432432
if (strpos($this->getHeader('Content-Type'), 'application/json') !== false) {
433433
$params = json_decode(file_get_contents($this->inputStream), true);
434-
if ($params !== null && \count($params) > 0) {
435-
$this->items['params'] = $params;
436-
if ($this->method === 'POST') {
437-
$this->items['post'] = $params;
434+
if (\is_array($params) && \count($params) > 0) {
435+
$this->items['params'] = $params;
436+
if ($this->method === 'POST') {
437+
$this->items['post'] = $params;
438+
}
438439
}
439-
}
440-
441440
// Handle application/x-www-form-urlencoded for methods other than GET
442441
// or post correctly
443442
} elseif ($this->method !== 'GET'

tests/lib/AppFramework/Http/RequestTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,20 @@ public function testJsonPost() {
207207
$this->assertSame('Joey', $request['nickname']);
208208
}
209209

210-
public function testNotJsonPost() {
210+
public function notJsonDataProvider() {
211+
return [
212+
['this is not valid json'],
213+
['"just a string"'],
214+
['{"just a string"}'],
215+
];
216+
}
217+
218+
/**
219+
* @dataProvider notJsonDataProvider
220+
*/
221+
public function testNotJsonPost($testData) {
211222
global $data;
212-
$data = 'this is not valid json';
223+
$data = $testData;
213224
$vars = [
214225
'method' => 'POST',
215226
'server' => ['CONTENT_TYPE' => 'application/json; utf-8']

0 commit comments

Comments
 (0)