[BUGFIX] RequestBuilder must not call $request->setMethod with NULL
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 13 Apr 2013 11:07:22 +0000 (13:07 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 13 Apr 2013 11:16:17 +0000 (13:16 +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/19901
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 af8e623..b4742c7 100644 (file)
@@ -163,7 +163,8 @@ class Tx_Extbase_MVC_Web_RequestBuilder implements t3lib_Singleton {
                $request->setControllerActionName($actionName);
                $request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
                $request->setBaseURI(t3lib_div::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));
index 6527883..0c31ced 100644 (file)
@@ -315,5 +315,27 @@ class Tx_Extbase_Tests_Unit_MVC_Web_RequestBuilderTest extends Tx_Extbase_Tests_
                $actualResult = $this->requestBuilder->_get('allowedControllerActions');
                $this->assertEquals($expectedResult, $actualResult);
        }
+
+       /**
+        * @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