Merge pull request #35797 from nextcloud/backport/35779/stable25

[stable25] [PHP8] check if params given to API are really an array
This commit is contained in:
Vincent Petry 2022-12-16 16:14:56 +01:00 committed by GitHub
commit 78dd4c65fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -431,13 +431,12 @@ class Request implements \ArrayAccess, \Countable, IRequest {
// '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'

View file

@ -207,9 +207,20 @@ class RequestTest extends \Test\TestCase {
$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']