]> source.dussan.org Git - nextcloud-server.git/commitdiff
check if params given to API are really an array 35796/head
authorArtur Neumann <artur@jankaritech.com>
Thu, 15 Dec 2022 07:21:02 +0000 (13:06 +0545)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Fri, 16 Dec 2022 10:50:41 +0000 (10:50 +0000)
Signed-off-by: Artur Neumann <artur@jankaritech.com>
lib/private/AppFramework/Http/Request.php
tests/lib/AppFramework/Http/RequestTest.php

index 010d889070e19646f5f9e8d48bdab43af7c89ca5..770946c80d557959c0c9a3f7cac3b40ea639f5b2 100644 (file)
@@ -429,13 +429,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'
index e15f3fe656cbada0fb2822e1768c1ac44506dfab..cd488225739059e3cfdd688f195eaac46e7c38a8 100644 (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']