From 492eba3a8ba20c9e42dbddd6da58a9bae4369d81 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 16 Jan 2022 15:54:22 +0100 Subject: [PATCH] Fixed duplicated slashes generated in path when doing not-found redirects with placeholders --- module/Core/src/Config/NotFoundRedirectResolver.php | 5 ++++- module/Core/test/Config/NotFoundRedirectResolverTest.php | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/module/Core/src/Config/NotFoundRedirectResolver.php b/module/Core/src/Config/NotFoundRedirectResolver.php index 531254f7..caa100c3 100644 --- a/module/Core/src/Config/NotFoundRedirectResolver.php +++ b/module/Core/src/Config/NotFoundRedirectResolver.php @@ -70,7 +70,10 @@ class NotFoundRedirectResolver implements NotFoundRedirectResolverInterface $replacePlaceholderForPattern(self::DOMAIN_PLACEHOLDER, $domain, $modifier), $replacePlaceholderForPattern(self::ORIGINAL_PATH_PLACEHOLDER, $path, $modifier), ); - $replacePlaceholdersInPath = $replacePlaceholders('\Functional\id'); + $replacePlaceholdersInPath = compose( + $replacePlaceholders('\Functional\id'), + static fn (?string $path) => $path === null ? null : str_replace('//', '/', $path), // Fix duplicated bars + ); $replacePlaceholdersInQuery = $replacePlaceholders('\urlencode'); return $redirectUri diff --git a/module/Core/test/Config/NotFoundRedirectResolverTest.php b/module/Core/test/Config/NotFoundRedirectResolverTest.php index 0dc25768..aa98d102 100644 --- a/module/Core/test/Config/NotFoundRedirectResolverTest.php +++ b/module/Core/test/Config/NotFoundRedirectResolverTest.php @@ -99,7 +99,7 @@ class NotFoundRedirectResolverTest extends TestCase new NotFoundRedirectOptions([ 'regular404' => 'https://redirect-here.com/{ORIGINAL_PATH}/{DOMAIN}/?d={DOMAIN}&p={ORIGINAL_PATH}', ]), - 'https://redirect-here.com//foo/bar/doma.in/?d=doma.in&p=%2Ffoo%2Fbar', // TODO Fix duplicated slash + 'https://redirect-here.com/foo/bar/doma.in/?d=doma.in&p=%2Ffoo%2Fbar', ]; yield 'invalid short URL' => [ new Uri('/foo'), @@ -111,7 +111,7 @@ class NotFoundRedirectResolverTest extends TestCase new Uri('/foo'), $this->notFoundType($this->requestForRoute(RedirectAction::class)), new NotFoundRedirectOptions(['invalidShortUrl' => 'https://redirect-here.com/{ORIGINAL_PATH}']), - 'https://redirect-here.com//foo', // TODO Fix duplicated slash + 'https://redirect-here.com/foo', ]; }