mirror of
https://github.com/nextcloud/server.git
synced 2026-04-01 23:25:47 -04:00
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:
commit
78dd4c65fe
2 changed files with 14 additions and 4 deletions
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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']
|
||||
|
|
|
|||
Loading…
Reference in a new issue