Fixed dropped query params when ? is preceded with / [#2964]

This commit is contained in:
Matias Griese
2020-12-11 15:32:09 +02:00
parent b6c941fc3e
commit 26f4d05e87
4 changed files with 19 additions and 20 deletions

View File

@@ -18,6 +18,7 @@
* Fixed broken check if php exif module is enabled in `ImageFile::fixOrientation()`
* Fixed `StaticResizeTrait::resize()` bad image height/width attributes if `null` values are passed to the method
* Fixed twig script/style tag `{% script 'file.js' at 'bottom' %}`, replaces broken `in` operator [#3084](https://github.com/getgrav/grav/issues/3084)
* Fixed dropped query params when `?` is preceded with `/` [#2964](https://github.com/getgrav/grav/issues/2964)
# v1.7.0-rc.19
## 12/02/2020

View File

@@ -98,12 +98,13 @@ trait PageRoutableTrait
{
$grav = Grav::instance();
$uri = $grav['uri'];
/** @var Pages $pages */
$pages = $grav['pages'];
$uri_path = rtrim(urldecode($uri->path()), '/');
$routes = $pages->routes();
if (isset($routes[$uri_path])) {
$page = $pages->dispatch($uri->route(), false, false);
$page = $pages->find($uri->route());
/** @var PageInterface|null $child_page */
$child_page = $page ? $page->parent() : null;
while ($child_page && !$child_page->root()) {

View File

@@ -25,6 +25,7 @@ use Grav\Framework\Session\Exceptions\SessionException;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\SyslogHandler;
use Monolog\Logger;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
@@ -100,14 +101,16 @@ class InitializeProcessor extends ProcessorBase
$this->initializePages($config);
// Initialize URI.
$uri = $this->initializeUri($config);
$this->initializeUri($config);
// Grav may return redirect response right away.
$response = $this->handleRedirectRequest($config, $uri);
if ($response) {
$this->stopTimer('_init');
if ($config->get('system.pages.redirect_trailing_slash', false)) {
$response = $this->handleRedirectRequest($request);
if ($response) {
$this->stopTimer('_init');
return $response;
return $response;
}
}
// Load accounts (decides class to be used).
@@ -363,7 +366,7 @@ class InitializeProcessor extends ProcessorBase
}
protected function initializeUri(Config $config): Uri
protected function initializeUri(Config $config): void
{
$this->startTimer('_init_uri', 'Initialize URI');
@@ -374,23 +377,17 @@ class InitializeProcessor extends ProcessorBase
$uri->init();
$this->stopTimer('_init_uri');
return $uri;
}
protected function handleRedirectRequest(Config $config, Uri $uri): ?ResponseInterface
protected function handleRedirectRequest(RequestInterface $request): ?ResponseInterface
{
$grav = $this->container;
// Redirect pages with trailing slash if configured to do so.
$path = $uri->path() ?: '/';
if ($path !== '/'
&& $config->get('system.pages.redirect_trailing_slash', false)
&& Utils::endsWith($path, '/')
) {
$redirect = $uri::getCurrentRoute()->toString();
$uri = $request->getUri();
$path = $request->getUri()->getPath() ?: '/';
return $grav->getRedirectResponse($redirect);
if ($path !== '/' && Utils::endsWith($path, '/')
) {
return $this->container->getRedirectResponse((string)$uri->withPath(rtrim($path, '/')));
}
return null;

View File

@@ -504,7 +504,7 @@ trait PageRoutableTrait
if (isset($routes[$uri_path])) {
/** @var PageInterface $child_page|null */
$child_page = $pages->dispatch($uri->route())->parent();
$child_page = $pages->find($uri->route())->parent();
if (null !== $child_page) {
while (!$child_page->root()) {
if ($this->path() === $child_page->path()) {