[BUGFIX] Consider subfolder in absolute links 50/37750/3
authorMarkus Klein <klein.t3@reelworx.at>
Thu, 24 Jul 2014 18:44:23 +0000 (20:44 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Thu, 12 Mar 2015 20:02:15 +0000 (21:02 +0100)
Ensure typolink considers the subfolder an instance might be running in
when creating absolute URLs and absRefPrefix is not set.

Resolves: #60545
Releases: master, 6.2
Change-Id: I8d3c2edc46bd01a9aa061cb695cb8795812cd305
Reviewed-on: http://review.typo3.org/37750
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index a83e167..a72f495 100644 (file)
@@ -6243,6 +6243,12 @@ class ContentObjectRenderer {
                                        $urlParts['scheme'] = 'http';
                                        $urlParts['host'] = $this->getEnvironmentVariable('HTTP_HOST');
                                        $urlParts['path'] = '/' . ltrim($urlParts['path'], '/');
+                                       // absRefPrefix has been prepended to $url beforehand
+                                       // so we only modify the path if no absRefPrefix has been set
+                                       // otherwise we would destroy the path
+                                       if ($GLOBALS['TSFE']->absRefPrefix === '') {
+                                               $urlParts['path'] = $this->getEnvironmentVariable('TYPO3_SITE_PATH') . ltrim($urlParts['path'], '/');
+                                       }
                                        $isUrlModified = TRUE;
                                }
                                // Override scheme:
index 9a2eb8d..71e6f24 100644 (file)
@@ -2605,6 +2605,7 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                array('TYPO3_SITE_PATH', '/'),
                        )
                ));
+               $GLOBALS['TSFE']->absRefPrefix = '';
 
                $this->assertEquals($expected, $this->cObj->_call('forceAbsoluteUrl', $url, $configuration));
        }
@@ -2693,4 +2694,26 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        )
                );
        }
+
+       /**
+        * @test
+        */
+       public function forceAbsoluteUrlReturnsCorrectAbsoluteUrlWithSubfolder() {
+               // Force hostname and subfolder
+               $this->cObj->expects($this->any())->method('getEnvironmentVariable')->will($this->returnValueMap(
+                       array(
+                               array('HTTP_HOST', 'localhost'),
+                               array('TYPO3_SITE_PATH', '/subfolder/'),
+                       )
+               ));
+
+               $expected = 'http://localhost/subfolder/fileadmin/my.pdf';
+               $url = 'fileadmin/my.pdf';
+               $configuration = array(
+                       'forceAbsoluteUrl' => '1'
+               );
+
+               $this->assertEquals($expected, $this->cObj->_call('forceAbsoluteUrl', $url, $configuration));
+       }
+
 }