From 9f61748dcb204ce1ae08c957f0a4c99a7ec81844 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Mon, 23 Sep 2024 14:59:57 +0200 Subject: [PATCH] fix(search): avoid server error without search query --- src/Controller/SearchController.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index c51722e..b6c8e14 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -14,6 +14,7 @@ namespace MonsieurBiz\SyliusSearchPlugin\Controller; use MonsieurBiz\SyliusSearchPlugin\Exception\UnknownRequestTypeException; +use MonsieurBiz\SyliusSearchPlugin\Form\Type\SearchType; use MonsieurBiz\SyliusSearchPlugin\Model\Documentable\DocumentableInterface; use MonsieurBiz\SyliusSearchPlugin\Search\Request\RequestConfiguration; use MonsieurBiz\SyliusSearchPlugin\Search\Request\RequestInterface; @@ -98,8 +99,15 @@ public function searchAction( */ public function postAction(Request $request): RedirectResponse { - $query = (array) ($request->request->all()['monsieurbiz_searchplugin_search'] ?? []); - $query = $query['query'] ?? ''; + $form = $this->createForm(SearchType::class); + $form->handleRequest($request); + if (!$form->isSubmitted() || !$form->isValid()) { + throw $this->createNotFoundException(); + } + + /** @var array $data */ + $data = $form->getData(); + $query = $data['query'] ?? ''; // With Apache a URL with a encoded slash (%2F) is provoking a 404 error on the server level return $this->redirect(