[BUGFIX] RequestBuilder must not call $request->setMethod with NULL
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 13 Apr 2013 10:10:46 +0000 (12:10 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 13 Apr 2013 11:27:21 +0000 (13:27 +0200)
If running a cli script the variable $_SERVER['REQUEST_METHOD'] is
not set at all. So when dispatching a sub webrequest the variable is
still not set and the RequestBuilder sets the method of Request to
NULL which is not allowed.

Therefore the variable will now be fetched from the Environment
and falls back to "GET" in case no value can be fetched this way.

Releases: 6.1, 6.0, 4.7, 1.3
Resolves: #13845
Change-Id: I5e33aba48605895f9eae1e3b710364091e7e84f0
Reviewed-on: https://review.typo3.org/19889
Reviewed-by: Stefan Neufeind
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Mvc/Web/RequestBuilder.php
typo3/sysext/extbase/Tests/Unit/Mvc/Web/RequestBuilderTest.php

index a7a1dfd..b230268 100644 (file)
@@ -169,7 +169,8 @@ class RequestBuilder implements \TYPO3\CMS\Core\SingletonInterface {
                $request->setControllerActionName($actionName);
                $request->setRequestUri(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
                $request->setBaseUri(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
-               $request->setMethod(isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : NULL);
+               $request->setMethod(isset($_SERVER['REQUEST_METHOD']) && is_string($_SERVER['REQUEST_METHOD']) ?
+                       $_SERVER['REQUEST_METHOD'] : 'GET');
                if (is_string($parameters['format']) && strlen($parameters['format'])) {
                        $request->setFormat(filter_var($parameters['format'], FILTER_SANITIZE_STRING));
                } else {
index 60b56e8..9da85e6 100644 (file)
@@ -757,6 +757,28 @@ class RequestBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $result = $requestBuilder->_call('untangleFilesArray', $convolutedFiles);
                $this->assertSame($untangledFiles, $result);
        }
+
+       /**
+        * @test
+        */
+       public function buildSetsRequestMode() {
+               $this->injectDependencies();
+               $expectedMethod = 'SomeRequestMethod';
+               $_SERVER['REQUEST_METHOD'] = $expectedMethod;
+               $this->mockRequest->expects($this->once())->method('setMethod')->with($expectedMethod);
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
+        */
+       public function buildSetsRequestModeReturnsGETIfNoMethodIsGiven() {
+               $this->injectDependencies();
+               $expectedMethod = '';
+               $_SERVER['REQUEST_METHOD'] = $expectedMethod;
+               $this->mockRequest->expects($this->once())->method('setMethod')->with($expectedMethod)->will($this->returnValue(array('GET')));
+               $this->requestBuilder->build();
+       }
 }
 
 ?>
\ No newline at end of file