Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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