[BUGFIX] UriBuilder: Do not skip empty parameters 04/51704/4
authorMarkus Klein <markus.klein@typo3.org>
Wed, 15 Feb 2017 15:55:41 +0000 (16:55 +0100)
committerBenni Mack <benni@typo3.org>
Thu, 16 Feb 2017 14:44:02 +0000 (15:44 +0100)
This is not the job of the uri builder to decide this.
It must simply build an URL from all given parameters.

In general, empty parameters can be intended by a dev.

Resolves: #79835
Releases: master, 7.6
Change-Id: I0ec3e7c41a78b40ecd81e52381f1d744a1e65608
Reviewed-on: https://review.typo3.org/51704
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Tested-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Routing/UriBuilder.php
typo3/sysext/extbase/Classes/Mvc/Web/Routing/UriBuilder.php
typo3/sysext/extbase/Tests/Unit/Mvc/Web/Routing/UriBuilderTest.php

index fc5c1ed..ef847e0 100644 (file)
@@ -160,7 +160,7 @@ class UriBuilder
      */
     protected function buildUri($parameters, $referenceType)
     {
-        $uri = 'index.php?' . ltrim(GeneralUtility::implodeArrayForUrl('', $parameters, '', true, true), '&');
+        $uri = 'index.php?' . ltrim(GeneralUtility::implodeArrayForUrl('', $parameters, '', false, true), '&');
         if ($referenceType === self::ABSOLUTE_PATH) {
             $uri = PathUtility::getAbsoluteWebPath(PATH_typo3 . $uri);
         } else {
index f6e7de6..171c150 100644 (file)
@@ -639,6 +639,7 @@ class UriBuilder
      */
     public function buildBackendUri()
     {
+        $arguments = [];
         if ($this->addQueryString === true) {
             if ($this->addQueryStringMethod) {
                 switch ($this->addQueryStringMethod) {
@@ -665,10 +666,14 @@ class UriBuilder
                 $arguments = ArrayUtility::arrayDiffAssocRecursive($arguments, $argumentToBeExcluded);
             }
         } else {
-            $arguments = [
-                'M' => GeneralUtility::_GP('M'),
-                'id' => GeneralUtility::_GP('id')
-            ];
+            $id = GeneralUtility::_GP('id');
+            $module = GeneralUtility::_GP('M');
+            if ($id !== null) {
+                $arguments['id'] = $id;
+            }
+            if ($module !== null) {
+                $arguments['M'] = $module;
+            }
         }
         ArrayUtility::mergeRecursiveWithOverrule($arguments, $this->arguments);
         $arguments = $this->convertDomainObjectsToIdentityArrays($arguments);
index 388a66c..7b0e7f2 100644 (file)
@@ -251,7 +251,7 @@ class UriBuilderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                     'M',
                     'id'
                 ],
-                '/typo3/index.php?moduleToken=dummyToken&foo=bar&foo2=bar2'
+                '/typo3/index.php?M=&moduleToken=dummyToken&foo=bar&foo2=bar2'
             ],
             'Arguments to be excluded in the end' => [
                 [
@@ -266,7 +266,7 @@ class UriBuilderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                     'M',
                     'id'
                 ],
-                '/typo3/index.php?moduleToken=dummyToken&foo=bar&foo2=bar2'
+                '/typo3/index.php?M=&moduleToken=dummyToken&foo=bar&foo2=bar2'
             ],
             'Arguments in nested array to be excluded' => [
                 [
@@ -419,7 +419,7 @@ class UriBuilderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         ];
         $this->uriBuilder->setAddQueryString(true);
         $this->uriBuilder->setAddQueryStringMethod('POST,GET');
-        $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('/typo3/index.php?moduleToken=dummyToken&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
+        $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('/typo3/index.php?M=&moduleToken=dummyToken&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
         $actualResult = $this->uriBuilder->buildBackendUri();
         $this->assertEquals($expectedResult, $actualResult);
     }
@@ -452,7 +452,7 @@ class UriBuilderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         ];
         $this->uriBuilder->setAddQueryString(true);
         $this->uriBuilder->setAddQueryStringMethod('GET,POST');
-        $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('/typo3/index.php?moduleToken=dummyToken&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
+        $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('/typo3/index.php?M=&moduleToken=dummyToken&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
         $actualResult = $this->uriBuilder->buildBackendUri();
         $this->assertEquals($expectedResult, $actualResult);
     }