[BUGFIX] Add also the "/" slash to ROUTE_PATH_DELIMITERS array 23/59123/5
authorRalf Merz <mail@merzilla.de>
Wed, 12 Dec 2018 16:43:14 +0000 (17:43 +0100)
committerBenni Mack <benni@typo3.org>
Tue, 8 Jan 2019 15:00:46 +0000 (16:00 +0100)
This is needed so that the PageType routeEnhancer is able to build URL
with a single trailing slash.
In other words, this fixes that a double trailing slash was created.

The functional test pageTypeDecoratorIsApplied gets extended with 2
instruction scenarios to set routeEnhancer PageTypeDecorator to
have a trailing slash instead of .html suffix tested, too.

Resolves: #86557
Releases: master, 9.5
Change-Id: If03bad8f054dc659f8870a98e064d9869597e8ba
Reviewed-on: https://review.typo3.org/59123
Reviewed-by: Michael Giek <michael.giek@web.de>
Tested-by: Michael Giek <michael.giek@web.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Routing/Enhancer/PageTypeDecorator.php
typo3/sysext/frontend/Tests/Functional/SiteHandling/EnhancerLinkGeneratorTest.php

index 9a0b53f..bea2d7f 100644 (file)
@@ -36,7 +36,7 @@ use TYPO3\CMS\Core\Routing\RouteCollection;
  */
 class PageTypeDecorator extends AbstractEnhancer implements DecoratingEnhancerInterface
 {
-    protected const ROUTE_PATH_DELIMITERS = ['.', '-', '_'];
+    protected const ROUTE_PATH_DELIMITERS = ['.', '-', '_', '/'];
 
     /**
      * @var array
index dd96f1a..baeead7 100644 (file)
@@ -108,6 +108,7 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
      * @param array $enhancers
      * @param string $variableName
      * @param array $templateOptions
+     * @param array $pageTypeSettings
      * @return array
      */
     protected function createDataSet(
@@ -115,7 +116,8 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
         array $languages,
         array $enhancers,
         string $variableName = 'value',
-        array $templateOptions = []
+        array $templateOptions = [],
+        array $pageTypeSettings
     ): array {
         $dataSet = [];
         foreach ($enhancers as $enhancer) {
@@ -128,6 +130,7 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
                     $enhancer['parameters'],
                     $languageId,
                     $expectation,
+                    $pageTypeSettings,
                 ];
             }
         }
@@ -247,7 +250,8 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
                 'additionalParameters' => $options['additionalParameters'] ?? ''
             ]),
             'enhance_name',
-            ['prefix' => 'localeModifier/']
+            ['prefix' => 'localeModifier/'],
+            array_key_exists('pageTypeSettings', $options) ? $options['pageTypeSettings'] : []
         );
     }
 
@@ -312,7 +316,8 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
                 'additionalParameters' => $options['additionalParameters'] ?? ''
             ]),
             'value',
-            ['prefix' => 'persistedAliasMapper/']
+            ['prefix' => 'persistedAliasMapper/'],
+            array_key_exists('pageTypeSettings', $options) ? $options['pageTypeSettings'] : []
         );
     }
 
@@ -377,7 +382,8 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
                 'additionalParameters' => $options['additionalParameters'] ?? ''
             ]),
             'value',
-            ['prefix' => 'persistedPatternMapper/']
+            ['prefix' => 'persistedPatternMapper/'],
+            array_key_exists('pageTypeSettings', $options) ? $options['pageTypeSettings'] : []
         );
     }
 
@@ -449,7 +455,8 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
                 'additionalParameters' => $options['additionalParameters'] ?? ''
             ]),
             'value',
-            ['prefix' => 'staticValueMapper/']
+            ['prefix' => 'staticValueMapper/'],
+            array_key_exists('pageTypeSettings', $options) ? $options['pageTypeSettings'] : []
         );
     }
 
@@ -520,7 +527,8 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
                     [
                         'prefix' => 'staticRangeMapper/',
                         'suffix' => sprintf(', value:%d', $value),
-                    ]
+                    ],
+                    array_key_exists('pageTypeSettings', $options) ? $options['pageTypeSettings'] : []
                 )
             );
         }
@@ -568,9 +576,45 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
     public function pageTypeDecoratorIsAppliedDataProvider(): array
     {
         $instructions = [
-            ['pathSuffix' => '.html', 'type' => null],
-            ['pathSuffix' => '.html', 'type' => 0],
-            ['pathSuffix' => '/menu.json', 'type' => 10],
+            [
+                'pathSuffix' => '.html',
+                'type' => null,
+                'pageTypeSettings' => $this->createPageTypeDecorator()
+            ],
+            [
+                'pathSuffix' => '.html',
+                'type' => 0,
+                'pageTypeSettings' => $this->createPageTypeDecorator()
+            ],
+            [
+                'pathSuffix' => '/menu.json',
+                'type' => 10,
+                'pageTypeSettings' => $this->createPageTypeDecorator()
+            ],
+            [
+                'pathSuffix' => '/',
+                'type' => null,
+                'pageTypeSettings' => [
+                    'type' => 'PageType',
+                    'default' => '/',
+                    'index' => '/',
+                    'map' => [
+                        'menu.json' => 10,
+                    ]
+                ]
+            ],
+            [
+                'pathSuffix' => '/',
+                'type' => 0,
+                'pageTypeSettings' => [
+                    'type' => 'PageType',
+                    'default' => '/',
+                    'index' => '/',
+                    'map' => [
+                        'menu.json' => 10,
+                    ]
+                ]
+            ]
         ];
 
         $dataSet = [];
@@ -584,7 +628,8 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
                 'pathSuffix' => $instruction['pathSuffix'],
                 'additionalParameters' => $instruction['type'] !== null
                     ? '&type=' . $instruction['type']
-                    : ''
+                    : '',
+                'pageTypeSettings' => $instruction['pageTypeSettings']
             ];
             $dataSetCandidates = array_merge(
                 $this->localeModifierDataProvider($dataProviderOptions),
@@ -612,16 +657,21 @@ class EnhancerLinkGeneratorTest extends AbstractTestCase
      * @param string $additionalParameters
      * @param int $targetLanguageId
      * @param string $expectation
+     * @param array $pageTypeSettings
      *
      * @test
      * @dataProvider pageTypeDecoratorIsAppliedDataProvider
      */
-    public function pageTypeDecoratorIsApplied(array $enhancer, string $additionalParameters, int $targetLanguageId, string $expectation)
+    public function pageTypeDecoratorIsApplied(array $enhancer, string $additionalParameters, int $targetLanguageId, string $expectation, array $pageTypeSettings)
     {
+        if (empty($pageTypeSettings)) {
+            $pageTypeSettings = $this->createPageTypeDecorator();
+        }
+
         $this->mergeSiteConfiguration('acme-com', [
             'routeEnhancers' => [
                 'Enhancer' => $enhancer,
-                'PageType' => $this->createPageTypeDecorator()
+                'PageType' => $pageTypeSettings
             ]
         ]);