Fixed double (and sometimes triple) slash in URLs
This commit is contained in:
parent
c50c368d2f
commit
79f9ab9950
4 changed files with 31 additions and 22 deletions
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -155,7 +155,9 @@
|
|||
<?php endif ?>
|
||||
|
||||
<li class="search">
|
||||
<form name="search" action="<?= \Chibi\Router::linkTo(['PostController', 'listView']) ?>" method="get">
|
||||
<form method="post"
|
||||
action="<?= \Chibi\Router::linkTo(['PostController', 'listRedirectAction']) ?>"
|
||||
name="search">
|
||||
|
||||
<input
|
||||
class="autocomplete"
|
||||
|
|
|
@ -27,6 +27,7 @@ $postValidation =
|
|||
'query' => '[^\/]*',
|
||||
'additionalInfo' => '[^\/]*',
|
||||
'score' => '-1|0|1',
|
||||
'page' => '\d*',
|
||||
];
|
||||
|
||||
\Chibi\Router::register(['PostController', 'uploadView'], 'GET', '/posts/upload', $postValidation);
|
||||
|
@ -36,9 +37,10 @@ $postValidation =
|
|||
\Chibi\Router::register(['PostController', 'deleteAction'], null, '/post/{id}/delete', $postValidation);
|
||||
|
||||
\Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{query}', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{page}', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{query}/{page}', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{additionalInfo}/{query}/{page}', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{query}/{additionalInfo}/{page}', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'listRedirectAction'], 'POST', '/{source}-redirect', $postValidation);
|
||||
|
||||
\Chibi\Router::register(['PostController', 'randomView'], 'GET', '/random', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'randomView'], 'GET', '/random/{page}', $postValidation);
|
||||
|
|
Loading…
Reference in a new issue