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:57:39 +0000 (18:57 +0000)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 30 Dec 2010 18:57:39 +0000 (18:57 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-3@9973 709f56b5-9817-0410-a4d7-c38de5d9e867

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

index 65cd5f3..e1b1927 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2010-12-29  Christian Kuhn  <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)
 
 2010-12-28  Oliver Hader  <oliver.hader@typo3.org>
index 5898d13..4725fa1 100644 (file)
@@ -3893,12 +3893,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 6691391..5b73a4e 100644 (file)
@@ -591,6 +591,40 @@ class t3lib_div_testcase extends tx_phpunit_testcase {
                $this->assertEquals($expectedResult, $result);
        }
 
+       /**
+        * @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 quoteJSvalue