From 354ecfb6875a26a70a86b8144c45a493882d91d5 Mon Sep 17 00:00:00 2001 From: Etienne Gutbub Date: Wed, 3 Jul 2024 16:52:19 +0200 Subject: [PATCH] feat(Encoded slash): Replace the encoded slash characters by a slash to avoid breaking Apache with it + avoid double encoding with filters --- src/Controller/SearchController.php | 3 ++- src/Resources/views/Search/_filters.html.twig | 4 ++-- src/Resources/views/Search/_tabs.html.twig | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index 49e5f0cc..9cf4de25 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -101,10 +101,11 @@ public function postAction(Request $request): RedirectResponse $query = (array) $request->request->all()['monsieurbiz_searchplugin_search'] ?? []; $query = $query['query'] ?? ''; + // With Apache a URL with a encoded slash (%2F) is provoking a 404 error on the server level return $this->redirect( $this->generateUrl( 'monsieurbiz_search_search', - ['query' => urlencode($query)] + ['query' => str_replace('%2F', '/', urlencode($query))] ) ); } diff --git a/src/Resources/views/Search/_filters.html.twig b/src/Resources/views/Search/_filters.html.twig index b183f236..fc435738 100644 --- a/src/Resources/views/Search/_filters.html.twig +++ b/src/Resources/views/Search/_filters.html.twig @@ -8,8 +8,8 @@ {{ 'monsieurbiz_searchplugin.filters.no_filter'|trans }} {% else %} - {% set encodedQuery = app.request.attributes.get('_route_params').query|default('')|url_encode %} - {% set path = path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge(app.request.query.all)|merge({query: encodedQuery})) %} + {% set searchQuery = app.request.attributes.get('_route_params').query|default('') %} + {% set path = path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge(app.request.query.all)|merge({query: searchQuery})) %}
{% for filter in result.filters %} diff --git a/src/Resources/views/Search/_tabs.html.twig b/src/Resources/views/Search/_tabs.html.twig index 21a6c47f..f4a05d72 100644 --- a/src/Resources/views/Search/_tabs.html.twig +++ b/src/Resources/views/Search/_tabs.html.twig @@ -1,12 +1,12 @@ {% if documentableRegistries|length > 1%}