From 79f9ab9950388de7f6e36f266cbffd35e46a113c Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 18 May 2014 21:11:45 +0200 Subject: [PATCH] Fixed double (and sometimes triple) slash in URLs --- src/Controllers/PostController.php | 38 +++++++++++++++++------------- src/Controllers/TagController.php | 5 ++-- src/Views/top-navigation.phtml | 4 +++- src/routes.php | 6 +++-- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 70db4d14..f980fa10 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -9,23 +9,6 @@ class PostController extends AbstractController try { - //redirect requests in form of /posts/?query=... to canonical address - $formQuery = InputHelper::get('query'); - if ($formQuery !== null) - { - $context->transport->searchQuery = $formQuery; - $context->transport->lastSearchQuery = $formQuery; - if (strpos($formQuery, '/') !== false) - throw new SimpleException('Search query contains invalid characters'); - - $url = \Chibi\Router::linkTo(['PostController', 'listView'], [ - 'source' => $source, - 'additionalInfo' => $additionalInfo, - 'query' => $formQuery]); - $this->redirect($url); - return; - } - $query = trim($query); $context->transport->searchQuery = $query; $context->transport->lastSearchQuery = $query; @@ -57,6 +40,27 @@ class PostController extends AbstractController $this->renderView('post-list-wrapper'); } + public function listRedirectAction($source = 'posts') + { + $context = Core::getContext(); + $query = trim(InputHelper::get('query')); + $context->transport->searchQuery = $query; + $context->transport->lastSearchQuery = $query; + if (strpos($query, '/') !== false) + throw new SimpleException('Search query contains invalid characters'); + + $params = []; + $params['source'] = $source; + if ($query) + $params['query'] = $query; + #if ($additionalInfo) + # $params['additionalInfo'] = $additionalInfo; + $params['page'] = 1; + + $url = \Chibi\Router::linkTo(['PostController', 'listView'], $params); + $this->redirect($url); + } + public function favoritesView($page = 1) { $this->listView('favmin:1', $page, 'favorites'); diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 4e278fec..a1ff0056 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -142,14 +142,15 @@ class TagController extends AbstractController $params = [ 'source' => 'mass-tag', - 'query' => $suppliedQuery ?: ' ', + 'query' => $suppliedQuery ?: '', 'additionalInfo' => $suppliedTag ? $suppliedTag : '', ]; if ($suppliedOldPage != 0 and $suppliedOldQuery == $suppliedQuery) $params['page'] = $suppliedOldPage; - $this->redirect(\Chibi\Router::linkTo(['PostController', 'listView'], $params)); + $url = \Chibi\Router::linkTo(['PostController', 'listView'], $params); + $this->redirect($url); } diff --git a/src/Views/top-navigation.phtml b/src/Views/top-navigation.phtml index 7bb40445..1219b05a 100644 --- a/src/Views/top-navigation.phtml +++ b/src/Views/top-navigation.phtml @@ -155,7 +155,9 @@