Fixed bug #15034: Login to backend fails with IPv6 Address as HTTP_HOST (Thanks to...
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 30 Dec 2010 18:55:24 +0000 (18:55 +0000)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 30 Dec 2010 18:55:24 +0000 (18:55 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9971 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
tests/t3lib/t3lib_divTest.php

index 9330bb8..6d90097 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
 
 2010-12-29  Christian Kuuhn  <lolli@schwarzbu.ch>
 
+       * Fixed bug #15034: Login to backend fails with IPv6 Address as HTTP_HOST (Thanks to Roland Schenke)
        * Fixed bug #10480: Add missing header in auto_respond_msg (Thanks to Christian Buelter)
        * Fixed bug #16849: [Unit tests] fixPermissions* tests rely on availability of posix_getegid() (Thanks to Steffen Gebert)
        * Fixed bug #11286: Caching of pagesections uses superfluos serialize() call (Thanks to Rupert Germann)
index 2e45f1e..12d1066 100644 (file)
@@ -4206,12 +4206,14 @@ final class t3lib_div {
                                $retVal = $DR;
                                break;
                        case 'TYPO3_HOST_ONLY':
-                               $p = explode(':', self::getIndpEnv('HTTP_HOST'));
-                               $retVal = $p[0];
+                               $httpHost = self::getIndpEnv('HTTP_HOST');
+                               $httpHostBracketPosition = strpos($httpHost, ']');
+                               $retVal = ($httpHostBracketPosition !== FALSE) ? substr($httpHost, 0, ($httpHostBracketPosition + 1)) : array_shift(explode(':', $httpHost));
                                break;
                        case 'TYPO3_PORT':
-                               $p = explode(':', self::getIndpEnv('HTTP_HOST'));
-                               $retVal = $p[1];
+                               $httpHost = self::getIndpEnv('HTTP_HOST');
+                               $httpHostOnly = self::getIndpEnv('TYPO3_HOST_ONLY');
+                               $retVal = (strlen($httpHost) > strlen($httpHostOnly)) ? substr($httpHost, strlen($httpHostOnly) + 1) : '';
                                break;
                        case 'TYPO3_REQUEST_HOST':
                                $retVal = (self::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://') .
index d9b288b..466fccc 100644 (file)
@@ -766,6 +766,40 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $this->assertEquals('/', $result[strlen($result) - 1]);
        }
 
+       /**
+        * @return array
+        */
+       public static function hostnameAndPortDataProvider() {
+               return array(
+                       'localhost ipv4 without port' => array('127.0.0.1', '127.0.0.1', ''),
+                       'localhost ipv4 with port' => array('127.0.0.1:81', '127.0.0.1', '81'),
+                       'localhost ipv6 without port' => array('[::1]', '[::1]', ''),
+                       'localhost ipv6 with port' => array('[::1]:81', '[::1]', '81'),
+                       'ipv6 without port' => array('[2001:DB8::1]', '[2001:DB8::1]', ''),
+                       'ipv6 with port' => array('[2001:DB8::1]:81', '[2001:DB8::1]', '81'),
+                       'hostname without port' => array('lolli.did.this', 'lolli.did.this', ''),
+                       'hostname with port' => array('lolli.did.this:42', 'lolli.did.this', '42'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider hostnameAndPortDataProvider
+        */
+       public function getIndpEnvTypo3HostOnlyParsesHostnamesAndIpAdresses($httpHost, $expectedIp) {
+               $_SERVER['HTTP_HOST'] = $httpHost;
+               $this->assertEquals($expectedIp, t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'));
+       }
+
+       /**
+        * @test
+        * @dataProvider hostnameAndPortDataProvider
+        */
+       public function getIndpEnvTypo3PortParsesHostnamesAndIpAdresses($httpHost, $dummy, $expectedPort) {
+               $_SERVER['HTTP_HOST'] = $httpHost;
+               $this->assertEquals($expectedPort, t3lib_div::getIndpEnv('TYPO3_PORT'));
+       }
+
 
        //////////////////////////////////
        // Tests concerning underscoredToUpperCamelCase