[BUGFIX] Allow to add type=0 to typolink syntax 99/59299/2
authorBenni Mack <benni@typo3.org>
Wed, 26 Dec 2018 23:21:34 +0000 (00:21 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 1 Jan 2019 19:11:14 +0000 (20:11 +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/59299
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/LinkHandling/LegacyLinkNotationConverter.php
typo3/sysext/core/Classes/LinkHandling/PageLinkHandler.php
typo3/sysext/core/Tests/Unit/LinkHandling/LegacyLinkNotationConverterTest.php

index ef7a0fe..7e4d9e0 100644 (file)
@@ -174,6 +174,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 e984084..939ec4c 100644 (file)
@@ -76,6 +76,27 @@ class LegacyLinkNotationConverterTest extends UnitTestCase
                 ],
                 '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',
                 [