mirror of
https://github.com/getgrav/grav.git
synced 2026-05-06 15:16:33 +02:00
Fixed dropped query params when ? is preceded with / [#2964]
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user