Skip to content

Commit

Permalink
fix(search): avoid server error without search query
Browse files Browse the repository at this point in the history
  • Loading branch information
delyriand committed Sep 23, 2024
1 parent 9122b37 commit 9f61748
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9f61748

Please sign in to comment.