Skip to content

Commit

Permalink
fix(controller): Fix false booleans in multipart/form-data
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Nov 27, 2024
1 parent 14f7e56 commit e2318f2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/private/AppFramework/Http/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,15 @@ private function executeController(Controller $controller, string $methodName):
if (($type === 'bool' || $type === 'boolean') &&
$value === 'false' &&
(
$this->request->method === 'GET' ||
str_contains($this->request->getHeader('Content-Type'),
'application/x-www-form-urlencoded')
$this->request->method === 'GET'
|| str_contains(
$this->request->getHeader('Content-Type'),
'application/x-www-form-urlencoded',
)
|| str_contains(
$this->request->getHeader('Content-Type'),
'multipart/form-data',
)
)
) {
$value = false;
Expand Down
35 changes: 35 additions & 0 deletions tests/lib/AppFramework/Http/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,41 @@ public function testResponseTransformedByAcceptHeader(): void {
$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(
Expand Down

0 comments on commit e2318f2

Please sign in to comment.