From fb8ad8fe9a7c6f68375fba0aea32a2b43d7c14b9 Mon Sep 17 00:00:00 2001 From: Dave Shoreman Date: Thu, 6 Apr 2017 04:16:40 +0100 Subject: [PATCH] Fix Internal Server Error for blank API requests Attempting to send an empty body to the create and update endpoints will result in Flarum outputting "Internal Server Error" as plain text, instead of failing gracefully with a json-ised validation exception. This commit adds an empty array as the third parameter to array_get, which sets the default value and thus allows Flarum to do its thing. --- extensions/tags/src/Api/Controller/CreateTagController.php | 2 +- extensions/tags/src/Api/Controller/UpdateTagController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/tags/src/Api/Controller/CreateTagController.php b/extensions/tags/src/Api/Controller/CreateTagController.php index c9e1e61c8..ec8ccc329 100644 --- a/extensions/tags/src/Api/Controller/CreateTagController.php +++ b/extensions/tags/src/Api/Controller/CreateTagController.php @@ -44,7 +44,7 @@ class CreateTagController extends AbstractCreateController protected function data(ServerRequestInterface $request, Document $document) { return $this->bus->dispatch( - new CreateTag($request->getAttribute('actor'), array_get($request->getParsedBody(), 'data')) + new CreateTag($request->getAttribute('actor'), array_get($request->getParsedBody(), 'data', [])) ); } } diff --git a/extensions/tags/src/Api/Controller/UpdateTagController.php b/extensions/tags/src/Api/Controller/UpdateTagController.php index 4f79259d4..0249183a6 100644 --- a/extensions/tags/src/Api/Controller/UpdateTagController.php +++ b/extensions/tags/src/Api/Controller/UpdateTagController.php @@ -45,7 +45,7 @@ class UpdateTagController extends AbstractResourceController { $id = array_get($request->getQueryParams(), 'id'); $actor = $request->getAttribute('actor'); - $data = array_get($request->getParsedBody(), 'data'); + $data = array_get($request->getParsedBody(), 'data', []); return $this->bus->dispatch( new EditTag($id, $actor, $data)