[+BUGFIX] baseUri is added on external links
authorSebastian Kurfuerst <sebastian@typo3.org>
Thu, 26 May 2011 17:13:31 +0000 (19:13 +0200)
committerSebastian Kurfuerst <sebastian@typo3.org>
Thu, 26 May 2011 17:13:31 +0000 (19:13 +0200)
On a redirect to an external URI via redirectToURI(),
the base URL is added by mistake.

Thanks to Michael Feinbier for this fix!

Change-Id: I641d5bd0de7ede81bf9ed6568290d554f9580138
Resolves: #10258

typo3/sysext/extbase/Classes/MVC/Controller/AbstractController.php
typo3/sysext/extbase/Tests/Unit/MVC/Controller/AbstractControllerTest.php

index 7501840..28cdf80 100644 (file)
@@ -333,7 +333,7 @@ abstract class Tx_Extbase_MVC_Controller_AbstractController implements Tx_Extbas
         */
        protected function addBaseUriIfNecessary($uri) {
                $baseUri = $this->request->getBaseURI();
-               if(stripos($uri, $baseUri) !== 0) {
+               if(stripos($uri, 'http://') !== 0 && stripos($uri, 'https://') !== 0) {
                        $uri = $baseUri . (string)$uri;
                }
                return $uri;
index e0099df..021dcef 100644 (file)
@@ -145,6 +145,21 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_AbstractControllerTest extends Tx_Ext
        /**
         * @test
         */
+       public function theBaseUriIsNotAddedIfExternalURI() {
+               $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
+               $mockRequest->expects($this->any())->method('getBaseURI')->will($this->returnValue('http://www.example.com/foo/'));
+
+               $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('dummy'), array(), '', FALSE);
+               $controller->_set('request', $mockRequest);
+               $actualResult = $controller->_call('addBaseUriIfNecessary', 'http://www.anotherexample.com/foo/bar/baz/boom.html');
+               $expectedResult = 'http://www.anotherexample.com/foo/bar/baz/boom.html';
+
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
+       /**
+        * @test
+        */
        public function theBaseUriIsNotAddedIfAlreadyExists() {
                $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
                $mockRequest->expects($this->any())->method('getBaseURI')->will($this->returnValue('http://www.example.com/foo/'));