From 2d5e14f527a3a29897503d9ed2df0b5b5478d74f Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 11 Nov 2025 20:35:59 +0200 Subject: [PATCH] resolve relative redirection targets (untested) --- src/Controller/Cli.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Controller/Cli.php b/src/Controller/Cli.php index ff1ca2f..cd81e73 100755 --- a/src/Controller/Cli.php +++ b/src/Controller/Cli.php @@ -213,17 +213,27 @@ class Cli { if ($this->redirects <= $this->option->follow) { + // Build new address + $target = new Address( + trim($response->getMeta()) + ); + + // Make relative links absolute + $target->toAbsolute( + $source + ); + // Validate redirection target location - if (filter_var($response->getMeta(), FILTER_VALIDATE_URL)) // @TODO resolve relative locations + if (filter_var($target->get(), FILTER_VALIDATE_URL)) { // Insert redirection target to the next destination - if (!$this->putSource($offset + 1, trim($response->getMeta()))) + if (!$this->putSource($offset + 1, $target->get())) { print( Message::red( sprintf( _("\tdestination could not be updated due to the conditions or it has already been indexed: `%s`"), - $response->getMeta() + $target->get() ) ) ); @@ -235,7 +245,7 @@ class Cli Message::red( sprintf( _("\tskip invalid redirection URL: `%s`"), - $response->getMeta() + $target->get() ) ) );