Skip to content

Commit

Permalink
check if params given to API are really an array
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Neumann <artur@jankaritech.com>
  • Loading branch information
individual-it committed Dec 15, 2022
1 parent 0d6a706 commit 81f2857
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,12 @@ protected function decodeContent() {
// 'application/json' must be decoded manually.
if (strpos($this->getHeader('Content-Type'), 'application/json') !== false) {
$params = json_decode(file_get_contents($this->inputStream), true);
if ($params !== null && \count($params) > 0) {
if (\is_array($params) && \count($params) > 0) {
$this->items['params'] = $params;
if ($this->method === 'POST') {
$this->items['post'] = $params;
}
}

// Handle application/x-www-form-urlencoded for methods other than GET
// or post correctly
} elseif ($this->method !== 'GET'
Expand Down
15 changes: 13 additions & 2 deletions tests/lib/AppFramework/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,20 @@ public function testJsonPost() {
$this->assertSame('Joey', $request['nickname']);
}

public function testNotJsonPost() {
public function notJsonDataProvider() {
return [
['this is not valid json'],
['"just a string"'],
['{"just a string"}'],
];
}

/**
* @dataProvider notJsonDataProvider
*/
public function testNotJsonPost($testData) {
global $data;
$data = 'this is not valid json';
$data = $testData;
$vars = [
'method' => 'POST',
'server' => ['CONTENT_TYPE' => 'application/json; utf-8']
Expand Down

0 comments on commit 81f2857

Please sign in to comment.