From a019a1b168b731d3c79565cefc57d0c25733e6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wolda=C5=84ski?= Date: Tue, 20 Jun 2023 08:38:51 +0200 Subject: [PATCH 1/2] [BUGFIX] Trim whitespaces in JSON decode helper Backport from 4.x --- .../Format/Json/DecodeViewHelper.php | 3 ++ .../Format/Json/DecodeViewHelperTest.php | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 Tests/Unit/ViewHelpers/Format/Json/DecodeViewHelperTest.php diff --git a/Classes/ViewHelpers/Format/Json/DecodeViewHelper.php b/Classes/ViewHelpers/Format/Json/DecodeViewHelper.php index c6b253f5..f3e85eaa 100644 --- a/Classes/ViewHelpers/Format/Json/DecodeViewHelper.php +++ b/Classes/ViewHelpers/Format/Json/DecodeViewHelper.php @@ -33,6 +33,9 @@ public function render() $json = $this->arguments['json']; if ($json === null) { $json = $this->renderChildren(); + if ($json !== null) { + $json = trim($json); + } if (empty($json)) { return null; } diff --git a/Tests/Unit/ViewHelpers/Format/Json/DecodeViewHelperTest.php b/Tests/Unit/ViewHelpers/Format/Json/DecodeViewHelperTest.php new file mode 100644 index 00000000..2579731a --- /dev/null +++ b/Tests/Unit/ViewHelpers/Format/Json/DecodeViewHelperTest.php @@ -0,0 +1,28 @@ +setArguments(['json' => null]); + $decodeViewHelper->setRenderChildrenClosure(function () { return "\n \n"; }); + $result = $decodeViewHelper->render(); + self::assertNull($result); + } +} From 70795860c98dcd0012bd080a9fb8d88d9602ed80 Mon Sep 17 00:00:00 2001 From: twoldanski <66474451+twoldanski@users.noreply.github.com> Date: Tue, 20 Jun 2023 12:26:17 +0200 Subject: [PATCH 2/2] [TASK] Normalize urls in all cases in order to avoid double slashes (#597) Resolves: #596 --- Classes/Utility/UrlUtility.php | 5 +++-- Tests/Unit/Utility/UrlUtilityTest.php | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Classes/Utility/UrlUtility.php b/Classes/Utility/UrlUtility.php index 84c49352..cd0c9746 100644 --- a/Classes/Utility/UrlUtility.php +++ b/Classes/Utility/UrlUtility.php @@ -25,7 +25,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use function array_merge; -use function count; use function rtrim; use function strpos; @@ -186,7 +185,9 @@ private function resolveWithVariants( array $variants = [], string $returnField = 'frontendBase' ): string { - if (count($variants) === 0) { + $frontendUrl = rtrim($frontendUrl, '/'); + + if ($variants === []) { return $frontendUrl; } diff --git a/Tests/Unit/Utility/UrlUtilityTest.php b/Tests/Unit/Utility/UrlUtilityTest.php index 6f6fcf54..4706e0d8 100644 --- a/Tests/Unit/Utility/UrlUtilityTest.php +++ b/Tests/Unit/Utility/UrlUtilityTest.php @@ -110,11 +110,11 @@ 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' => [ [ @@ -672,7 +672,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