From b5bbef70dbbb5eaf873f6b1e28144890ce392112 Mon Sep 17 00:00:00 2001 From: twoldanski <66474451+twoldanski@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:54:36 +0200 Subject: [PATCH] [TASK] Normalize urls in all cases in order to avoid double slashes (#598) Resolves: #596 --- Classes/Utility/UrlUtility.php | 1 + Tests/Unit/Utility/UrlUtilityTest.php | 30 +++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Classes/Utility/UrlUtility.php b/Classes/Utility/UrlUtility.php index 72d4875a..e1ff911f 100644 --- a/Classes/Utility/UrlUtility.php +++ b/Classes/Utility/UrlUtility.php @@ -201,6 +201,7 @@ private function resolveWithVariants( array $variants = [], string $returnField = 'frontendBase' ): string { + $frontendUrl = rtrim($frontendUrl, '/'); if ($variants === []) { return $frontendUrl; } diff --git a/Tests/Unit/Utility/UrlUtilityTest.php b/Tests/Unit/Utility/UrlUtilityTest.php index c2d6952c..493d6188 100644 --- a/Tests/Unit/Utility/UrlUtilityTest.php +++ b/Tests/Unit/Utility/UrlUtilityTest.php @@ -110,20 +110,20 @@ public function testFrontendUrlsWithBaseProductionAndLocalOverride(): void { $site = $this->prophesize(Site::class); $site->getConfiguration()->shouldBeCalled(3)->willReturn([ - 'base' => 'https://api.typo3.org', - 'frontendBase' => 'https://www.typo3.org', - 'frontendApiProxy' => 'https://www.typo3.org/headless', - 'frontendFileApi' => 'https://www.typo3.org/headless/fileadmin', - 'SpecialSitemapKey' => 'https://www.typo3.org/custom-sitemap', + 'base' => 'https://api.typo3.org/', + 'frontendBase' => 'https://www.typo3.org/', + 'frontendApiProxy' => 'https://www.typo3.org/headless/', + 'frontendFileApi' => 'https://www.typo3.org/headless/fileadmin/', + 'SpecialSitemapKey' => 'https://www.typo3.org/custom-sitemap/', 'languages' => [], 'baseVariants' => [ [ 'base' => 'https://test-backend-api.tld', 'condition' => 'applicationContext == "Development"', - 'frontendBase' => 'https://test-frontend.tld', - 'frontendApiProxy' => 'https://test-frontend-api.tld/headless', - 'frontendFileApi' => 'https://test-frontend-api.tld/headless/fileadmin', - 'SpecialSitemapKey' => 'https://test-frontend.tld/sitemap', + 'frontendBase' => 'https://test-frontend.tld/', + 'frontendApiProxy' => 'https://test-frontend-api.tld/headless/', + 'frontendFileApi' => 'https://test-frontend-api.tld/headless/fileadmin/', + 'SpecialSitemapKey' => 'https://test-frontend.tld/sitemap/', ], ] ]); @@ -722,9 +722,9 @@ public function testEdgeCases() 'hreflang' => 'en-us', 'direction' => 'ltr', 'flag' => 'us', - 'frontendBase' => 'https://frontend-domain-from-lang.tld', + 'frontendBase' => 'https://frontend-domain-from-lang.tld/', 'frontendApiProxy' => 'https://frontend-domain-from-lang.tld/headless/', - 'frontendFileApi' => 'https://frontend-domain-from-lang.tld/headless/fileadmin', + 'frontendFileApi' => 'https://frontend-domain-from-lang.tld/headless/fileadmin/', ])); $resolver = $this->prophesize(Resolver::class); @@ -732,7 +732,7 @@ public function testEdgeCases() $urlUtility = new UrlUtility(null, $resolver->reveal(), $siteFinder, $request->reveal()); self::assertSame('https://frontend-domain-from-lang.tld', $urlUtility->getFrontendUrl()); - self::assertSame('https://frontend-domain-from-lang.tld/headless/', $urlUtility->getProxyUrl()); + self::assertSame('https://frontend-domain-from-lang.tld/headless', $urlUtility->getProxyUrl()); self::assertSame('https://frontend-domain-from-lang.tld/headless/fileadmin', $urlUtility->getStorageProxyUrl()); // configuration on language lvl with variants @@ -794,9 +794,9 @@ public function testEdgeCases() [ 'base' => 'https://test-backend-api.tld', 'condition' => 'applicationContext == "Development"', - 'frontendBase' => 'https://test-frontend-from-from-request-lang.tld', - 'frontendApiProxy' => 'https://test-frontend-from-from-request-lang.tld/headless', - 'frontendFileApi' => 'https://test-frontend-from-from-request-lang.tld/headless/fileadmin' + 'frontendBase' => 'https://test-frontend-from-from-request-lang.tld/', + 'frontendApiProxy' => 'https://test-frontend-from-from-request-lang.tld/headless/', + 'frontendFileApi' => 'https://test-frontend-from-from-request-lang.tld/headless/fileadmin/' ], ], ]));