[BUGFIX] Allow to add type=0 to typolink syntax 21/59321/2
authorBenni Mack <benni@typo3.org>
Wed, 26 Dec 2018 23:21:34 +0000 (00:21 +0100)
committerBenni Mack <benni@typo3.org>
Fri, 4 Jan 2019 13:34:21 +0000 (14:34 +0100)
In previous versions, it was possible to link
to type=0 via "4,0,&param=2" where this was
stripped away, as the old syntax with the third
parameter was not supported anymore.

The patch changes the "empty()" to "isset()"
and explicitly sets the type parameter again.

Resolves: #81226
Releases: master, 9.5, 8.7
Change-Id: I5d19c38c90571f6686e7121dac638342783237ec
Reviewed-on: https://review.typo3.org/59321
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/LinkHandling/LegacyLinkNotationConverter.php
typo3/sysext/core/Classes/LinkHandling/PageLinkHandler.php
typo3/sysext/core/Tests/Unit/LinkHandling/LegacyLinkNotationConverterTest.php

index 776ca2b..9207724 100644 (file)
@@ -173,6 +173,7 @@ class LegacyLinkNotationConverter
             $result['pageuid'] = 'current';
             $result['fragment'] = substr($data, 1);
         } elseif (strpos($data, ',') !== false) {
+            $data = rtrim($data, ',');
             list($result['pageuid'], $result['pagetype']) = explode(',', $data, 2);
         } elseif (strpos($data, '/') !== false) {
             $data = explode('/', trim($data, '/'));
index 93ee385..52bbe18 100644 (file)
@@ -42,7 +42,8 @@ class PageLinkHandler implements LinkHandlingInterface
             $urn .= '?uid=' . $parameters['pageuid'];
         }
         $urn = rtrim($urn, ':');
-        if (!empty($parameters['pagetype'])) {
+        // Page type is set and not empty (= "0" in this case means it is not empty)
+        if (isset($parameters['pagetype']) && strlen((string)$parameters['pagetype']) > 0) {
             $urn .= '&type=' . $parameters['pagetype'];
         }
         if (!empty($parameters['parameters'])) {
index 37bd851..c642f08 100644 (file)
@@ -73,6 +73,27 @@ class LegacyLinkNotationConverterTest extends \TYPO3\TestingFramework\Core\Unit\
                 ],
                 't3://page?uid=13&type=31&unbel=ievable#uncool'
             ],
+            'page with type and parameters as another parameter and fragment - old style' => [
+                '13,31,&unbel=ievable&but=possibly#uncool',
+                [
+                    'type' => LinkService::TYPE_PAGE,
+                    'pageuid' => '13',
+                    'pagetype' => '31',
+                    'parameters' => 'unbel=ievable&but=possibly',
+                    'fragment' => 'uncool'
+                ],
+                't3://page?uid=13&type=31&unbel=ievable&but=possibly#uncool'
+            ],
+            'page with type and parameters as third parameter and explicitly allow type=0' => [
+                '1,0,&param=2',
+                [
+                    'type' => LinkService::TYPE_PAGE,
+                    'pageuid' => '1',
+                    'pagetype' => '0',
+                    'parameters' => 'param=2',
+                ],
+                't3://page?uid=1&type=0&param=2'
+            ],
             'page with alias - old style' => [
                 'alias13',
                 [