Skip to content

Commit

Permalink
Fix content representation regression
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Apr 14, 2024
1 parent f462e12 commit 602865f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/Retour/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kirby\Retour;

use Kirby\Exception\InvalidArgumentException;
use Kirby\Filesystem\F;
use Kirby\Http\Header;
use Kirby\Http\Response;
use Kirby\Http\Url;
Expand Down Expand Up @@ -140,13 +141,14 @@ public function toRoute(): array|false
return [
'pattern' => trim($this->from(), '/'),
'action' => function (...$placeholders) use ($redirect) {
$retour = Retour::instance();
$kirby = $retour->kirby();
$to = $redirect->to() ?? '/';
$parts = Str::split($to, '.');
$to = Redirect::toPath($parts[0], $placeholders);
$page = $kirby->page($to);
$code = $redirect->status();
$retour = Retour::instance();
$kirby = $retour->kirby();
$to = $redirect->to() ?? '/';
$to = Redirect::toPath($to, $placeholders);
$extension = F::extension($to);
$path = Str::beforeEnd($to, '.' . $extension);
$page = $kirby->page($path);
$code = $redirect->status();

// Add log entry
$retour->log()->add([
Expand All @@ -157,14 +159,16 @@ public function toRoute(): array|false
// Redirects
// @codeCoverageIgnoreStart
if ($code >= 300 && $code < 400) {
$url = $page?->url() ?? $to;
if ($page) {
$to = $page->url();

// support for content representations
if ($extension = $parts[1] ?? null) {
$url .= '.' . $extension;
// support for content representations
if (empty($extension) === false) {
$to .= '.' . $extension;
}
}

Response::go($url, $code);
Response::go($to, $code);
}
// @codeCoverageIgnoreEnd

Expand Down

0 comments on commit 602865f

Please sign in to comment.