diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-11-28 14:46:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-28 14:46:16 +0100 |
commit | dd101dd0f70fc740106c6db30b0742e4db772b08 (patch) | |
tree | 5e1f3b211866bc3187d2c844dafd150f6ef83a9d | |
parent | 379f575c25cdf4769d5c019394e73ac8b8f46385 (diff) | |
parent | 2b6da9eaeee33e7cbfc88960d7686d8d8b844bbd (diff) | |
download | nextcloud-server-dd101dd0f70fc740106c6db30b0742e4db772b08.tar.gz nextcloud-server-dd101dd0f70fc740106c6db30b0742e4db772b08.zip |
Merge pull request #49515 from nextcloud/bugfix/noid/boolean-false-in-multipart-form-data
fix(controller): Fix false booleans in multipart/form-data
-rw-r--r-- | build/psalm-baseline.xml | 3 | ||||
-rw-r--r-- | lib/private/AppFramework/Http/Dispatcher.php | 12 | ||||
-rw-r--r-- | tests/lib/AppFramework/Http/DispatcherTest.php | 41 |
3 files changed, 40 insertions, 16 deletions
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index ed96e4391f9..00add5ee78e 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -1384,9 +1384,6 @@ </UndefinedInterfaceMethod> </file> <file src="lib/private/AppFramework/Http/Dispatcher.php"> - <NoInterfaceProperties> - <code><![CDATA[$this->request->method]]></code> - </NoInterfaceProperties> <NullArgument> <code><![CDATA[null]]></code> </NullArgument> diff --git a/lib/private/AppFramework/Http/Dispatcher.php b/lib/private/AppFramework/Http/Dispatcher.php index e2750e30fa9..d63a9108b47 100644 --- a/lib/private/AppFramework/Http/Dispatcher.php +++ b/lib/private/AppFramework/Http/Dispatcher.php @@ -183,16 +183,8 @@ class Dispatcher { $value = $this->request->getParam($param, $default); $type = $this->reflector->getType($param); - // if this is submitted using GET or a POST form, 'false' should be - // converted to false - if (($type === 'bool' || $type === 'boolean') && - $value === 'false' && - ( - $this->request->method === 'GET' || - str_contains($this->request->getHeader('Content-Type'), - 'application/x-www-form-urlencoded') - ) - ) { + // Converted the string `'false'` to false when the controller wants a boolean + if ($value === 'false' && ($type === 'bool' || $type === 'boolean')) { $value = false; } elseif ($value !== null && \in_array($type, $types, true)) { settype($value, $type); diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php index 94bcfcc4af2..7415ecd9486 100644 --- a/tests/lib/AppFramework/Http/DispatcherTest.php +++ b/tests/lib/AppFramework/Http/DispatcherTest.php @@ -328,7 +328,7 @@ class DispatcherTest extends \Test\TestCase { $this->dispatcherPassthrough(); $response = $this->dispatcher->dispatch($controller, 'exec'); - $this->assertEquals('[3,true,4,1]', $response[3]); + $this->assertEquals('[3,false,4,1]', $response[3]); } @@ -361,7 +361,7 @@ class DispatcherTest extends \Test\TestCase { $this->dispatcherPassthrough(); $response = $this->dispatcher->dispatch($controller, 'exec'); - $this->assertEquals('[3,true,4,7]', $response[3]); + $this->assertEquals('[3,false,4,7]', $response[3]); } @@ -471,6 +471,41 @@ class DispatcherTest extends \Test\TestCase { $this->assertEquals('{"text":[3,false,4,1]}', $response[3]); } + public function testResponseTransformedBySendingMultipartFormData(): void { + $this->request = new Request( + [ + 'post' => [ + 'int' => '3', + 'bool' => 'false', + 'double' => 1.2, + ], + 'server' => [ + 'HTTP_ACCEPT' => 'application/text, test', + 'HTTP_CONTENT_TYPE' => 'multipart/form-data' + ], + 'method' => 'POST' + ], + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) + ); + $this->dispatcher = new Dispatcher( + $this->http, $this->middlewareDispatcher, $this->reflector, + $this->request, + $this->config, + \OC::$server->getDatabaseConnection(), + $this->logger, + $this->eventLogger, + $this->container + ); + $controller = new TestController('app', $this->request); + + // reflector is supposed to be called once + $this->dispatcherPassthrough(); + $response = $this->dispatcher->dispatch($controller, 'exec'); + + $this->assertEquals('{"text":[3,false,4,1]}', $response[3]); + } + public function testResponsePrimarilyTransformedByParameterFormat(): void { $this->request = new Request( @@ -506,7 +541,7 @@ class DispatcherTest extends \Test\TestCase { $this->dispatcherPassthrough(); $response = $this->dispatcher->dispatch($controller, 'exec'); - $this->assertEquals('{"text":[3,true,4,1]}', $response[3]); + $this->assertEquals('{"text":[3,false,4,1]}', $response[3]); } |