]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
Fix bug #161: URLs broken on 1&1 server
authorChristian Weiske <cweiske@cweiske.de>
Tue, 20 Aug 2013 18:58:28 +0000 (20:58 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 20 Aug 2013 18:58:28 +0000 (20:58 +0200)
doc/ChangeLog
src/SemanticScuttle/Environment.php
src/SemanticScuttle/constants.php
tests/SemanticScuttle/EnvironmentTest.php

index ff60527d7c2d11603942aa7420b26ec7c2d1a80e..ca26618a27b798c73c8f27acf2614d4c4b86c805 100644 (file)
@@ -3,6 +3,11 @@ ChangeLog for SemantiScuttle
 
 .. contents::
 
+0.98.6 - 2013-XX-XX
+-------------------
+- Fix bug #161: URLs broken on 1&1 server
+
+
 0.98.5 - 2013-03-20
 -------------------
 - Fix bug #109: preserve privacy setting from Delicious export files
index e5fe3dec43b7430bfc84d1877110b68df47b13c1..7ccb466bd562ed6fd7b452efa495f6d8d62fa05a 100644 (file)
@@ -29,24 +29,20 @@ class SemanticScuttle_Environment
      */
     public static function getServerPathInfo()
     {
-        /* old code that does not work today.
-           if you find that this code helps you, tell us
-           and send us the output of var_export($_SERVER);
-        // Correct bugs with PATH_INFO (maybe for Apache 1 or CGI) -- for 1&1 host...
-        if (isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO'])) {
-            if (strlen($_SERVER["PATH_INFO"])<strlen($_SERVER["ORIG_PATH_INFO"])) {
-                $_SERVER["PATH_INFO"] = $_SERVER["ORIG_PATH_INFO"];
-            }
-            if (strcasecmp($_SERVER["PATH_INFO"], $_SERVER["SCRIPT_NAME"]) == 0) {
-                unset($_SERVER["PATH_INFO"]);
-            }
-            if (strpos($_SERVER["PATH_INFO"], '.php') !== false) {
-                unset($_SERVER["PATH_INFO"]);
+        if (isset($_SERVER['PATH_INFO'])) {
+            return $_SERVER['PATH_INFO'];
+        }
+
+        if (isset($_SERVER['ORIG_PATH_INFO'])) {
+            //1&1 servers
+            if ($_SERVER['ORIG_PATH_INFO'] == $_SERVER['SCRIPT_NAME']) {
+                return '';
             }
+            return $_SERVER['ORIG_PATH_INFO'];
         }
-        */
 
-        return $_SERVER['PATH_INFO'];
+        //fallback when no special path after the php file is given
+        return '';
     }
 }
 ?>
\ No newline at end of file
index fcb2d902d292cdbc8e81c4f3ac3441a48650da46..306c32ac6f2e28ef8293d6350e48d7a6377deb57 100644 (file)
@@ -69,6 +69,6 @@ define('PAGE_WATCHLIST', "watchlist");
 // installations on the same host server
 define('INSTALLATION_ID', md5($GLOBALS['dbname'].$GLOBALS['tableprefix']));
 
-//currently not needed
-//$_SERVER['PATH_INFO'] = SemanticScuttle_Environment::getServerPathInfo();
+//fix PATH_INFO on certain hosts
+$_SERVER['PATH_INFO'] = SemanticScuttle_Environment::getServerPathInfo();
 ?>
index a41efa1c1dad5fe78a8574f94d3b78310f9308ca..3baa9ede11841a7e652feb657c4b0d486ef25fe4 100644 (file)
@@ -2,6 +2,42 @@
 
 class SemanticScuttle_EnvironmentTest extends PHPUnit_Framework_TestCase
 {
+    public function testServerPathInfoModPhpNoPath()
+    {
+        $_SERVER = array (
+            'HTTP_USER_AGENT' => 'Opera/9.80 (X11; Linux x86_64) Presto/2.12.388 Version/12.16',
+            'HTTP_HOST' => 'bm.bogo',
+            'HTTP_ACCEPT' => 'text/html, application/xml;q=0.9, applicaton/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1',
+            'HTTP_ACCEPT_LANGUAGE' => 'en,de-DE;q=0.9,de;q=0.8',
+            'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
+            'HTTP_CONNECTION' => 'Keep-Alive',
+            'HTTP_DNT' => '1',
+            'PATH' => '/usr/local/bin:/usr/bin:/bin',
+            'SERVER_SIGNATURE' => '<address>Apache/2.2.22 (Ubuntu) Server at bm.bogo Port 80</address>',
+            'SERVER_SOFTWARE' => 'Apache/2.2.22 (Ubuntu)',
+            'SERVER_NAME' => 'bm.bogo',
+            'SERVER_ADDR' => '127.0.0.1',
+            'SERVER_PORT' => '80',
+            'REMOTE_ADDR' => '127.0.0.1',
+            'DOCUMENT_ROOT' => '/var/www',
+            'SERVER_ADMIN' => '[no address given]',
+            'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/bm.bogo/test.php',
+            'REMOTE_PORT' => '38545',
+            'GATEWAY_INTERFACE' => 'CGI/1.1',
+            'SERVER_PROTOCOL' => 'HTTP/1.1',
+            'REQUEST_METHOD' => 'GET',
+            'QUERY_STRING' => '',
+            'REQUEST_URI' => '/test.php',
+            'SCRIPT_NAME' => '/test.php',
+            'PHP_SELF' => '/test.php',
+            'REQUEST_TIME_FLOAT' => 1377024570.296,
+            'REQUEST_TIME' => 1377024570,
+        );
+        $this->assertEquals(
+            '', SemanticScuttle_Environment::getServerPathInfo()
+        );
+    }
+
     public function testServerPathInfoModPhp()
     {
         $_SERVER = array(
@@ -90,6 +126,109 @@ class SemanticScuttle_EnvironmentTest extends PHPUnit_Framework_TestCase
         );
     }
 
+    public function testServerPathInfo1and1NoPath()
+    {
+        $_SERVER = array(
+            'REDIRECT_SCRIPT_URL' => '/dummy.php',
+            'REDIRECT_SCRIPT_URI' => 'http://www.example.org/dummy.php',
+            'REDIRECT_DOCUMENT_ROOT' => '/kunden/homepages/44/dexample/htdocs/example/www',
+            'REDIRECT_HANDLER' => 'x-mapp-php6',
+            'REDIRECT_STATUS' => '200',
+            'DBENTRY_HOST' => 'example.org',
+            'DBENTRY' => '/kunden/homepages/44/dexample/htdocs/example/www:d0000#CPU 6 #MEM 10240 #CGI 18 #NPROC 12 #TAID 46322755 #WERB 0 #LANG 2 #STAT 1',
+            'SCRIPT_URL' => '/dummy.php',
+            'SCRIPT_URI' => 'http://www.example.org/dummy.php',
+            'HTTP_USER_AGENT' => 'Opera/9.80 (X11; Linux x86_64) Presto/2.12.388 Version/12.16',
+            'HTTP_HOST' => 'www.example.org',
+            'HTTP_ACCEPT' => 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1',
+            'HTTP_ACCEPT_LANGUAGE' => 'en,de-DE;q=0.9,de;q=0.8',
+            'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
+            'HTTP_COOKIE' => 'PHPSESSID=8c7853d7f639b3c6d24c224cf7d4cb1c',
+            'HTTP_CONNECTION' => 'Keep-Alive',
+            'HTTP_DNT' => '1',
+            'PATH' => '/bin:/usr/bin',
+            'SERVER_SIGNATURE' => '',
+            'SERVER_SOFTWARE' => 'Apache',
+            'SERVER_NAME' => 'example.org',
+            'SERVER_ADDR' => '127.0.0.1',
+            'SERVER_PORT' => '80',
+            'REMOTE_ADDR' => '127.0.0.1',
+            'DOCUMENT_ROOT' => '/kunden/homepages/44/dexample/htdocs/example/www',
+            'SERVER_ADMIN' => 'webmaster@example.org',
+            'SCRIPT_FILENAME' => '/kunden/homepages/44/dexample/htdocs/example/www/dummy.php',
+            'REMOTE_PORT' => '35368',
+            'REDIRECT_URL' => '/dummy.php',
+            'GATEWAY_INTERFACE' => 'CGI/1.1',
+            'SERVER_PROTOCOL' => 'HTTP/1.1',
+            'REQUEST_METHOD' => 'GET',
+            'QUERY_STRING' => '',
+            'REQUEST_URI' => '/dummy.php',
+            'SCRIPT_NAME' => '/dummy.php',
+            'STATUS' => '200',
+            'ORIG_PATH_INFO' => '/dummy.php',
+            'ORIG_PATH_TRANSLATED' => '/kunden/homepages/44/dexample/htdocs/example/www/dummy.php',
+            'PHP_SELF' => '/dummy.php',
+            'REQUEST_TIME_FLOAT' => 1377022156.0101,
+            'REQUEST_TIME' => 1377022156,
+            'argv' => array(),
+            'argc' => 0,
+        );
+        $this->assertEquals(
+            '', SemanticScuttle_Environment::getServerPathInfo()
+        );
+    }
+
+    public function testServerPathInfo1and1WithPath()
+    {
+        $_SERVER = array(
+            'REDIRECT_SCRIPT_URL' => '/dummy.php/dummy/foo',
+            'REDIRECT_SCRIPT_URI' => 'http://www.example.org/dummy.php/dummy/foo',
+            'REDIRECT_DOCUMENT_ROOT' => '/kunden/homepages/44/dexample/htdocs/example/www',
+            'REDIRECT_HANDLER' => 'x-mapp-php6',
+            'REDIRECT_STATUS' => '200',
+            'DBENTRY_HOST' => 'example.org',
+            'DBENTRY' => '/kunden/homepages/44/dexample/htdocs/example/www:d0000#CPU 6 #MEM 10240 #CGI 18 #NPROC 12 #TAID 46322755 #WERB 0 #LANG 2 #STAT 1',
+            'SCRIPT_URL' => '/dummy.php/dummy/foo',
+            'SCRIPT_URI' => 'http://www.example.org/dummy.php/dummy/foo',
+            'HTTP_USER_AGENT' => 'Opera/9.80 (X11; Linux x86_64) Presto/2.12.388 Version/12.16',
+            'HTTP_HOST' => 'www.example.org',
+            'HTTP_ACCEPT' => 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1',
+            'HTTP_ACCEPT_LANGUAGE' => 'en,de-DE;q=0.9,de;q=0.8',
+            'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
+            'HTTP_COOKIE' => 'PHPSESSID=8c7853d7f639b3c6d24c224cf7d4cb1c',
+            'HTTP_CONNECTION' => 'Keep-Alive',
+            'HTTP_DNT' => '1',
+            'PATH' => '/bin:/usr/bin',
+            'SERVER_SIGNATURE' => '',
+            'SERVER_SOFTWARE' => 'Apache',
+            'SERVER_NAME' => 'example.org',
+            'SERVER_ADDR' => '127.0.0.1',
+            'SERVER_PORT' => '80',
+            'REMOTE_ADDR' => '127.0.0.1',
+            'DOCUMENT_ROOT' => '/kunden/homepages/44/dexample/htdocs/example/www',
+            'SERVER_ADMIN' => 'webmaster@example.org',
+            'SCRIPT_FILENAME' => '/kunden/homepages/44/dexample/htdocs/example/www/dummy.php',
+            'REMOTE_PORT' => '35857',
+            'REDIRECT_URL' => '/dummy.php/dummy/foo',
+            'GATEWAY_INTERFACE' => 'CGI/1.1',
+            'SERVER_PROTOCOL' => 'HTTP/1.1',
+            'REQUEST_METHOD' => 'GET',
+            'QUERY_STRING' => '',
+            'REQUEST_URI' => '/dummy.php/dummy/foo',
+            'SCRIPT_NAME' => '/dummy.php',
+            'STATUS' => '200',
+            'ORIG_PATH_INFO' => '/dummy/foo',
+            'ORIG_PATH_TRANSLATED' => '/kunden/homepages/44/dexample/htdocs/example/www/dummy.php',
+            'PHP_SELF' => '/dummy.php',
+            'REQUEST_TIME_FLOAT' => 1377024137.8098,
+            'REQUEST_TIME' => 1377024137,
+            'argv' => array(),
+            'argc' => 0,
+        );
+        $this->assertEquals(
+            '/dummy/foo', SemanticScuttle_Environment::getServerPathInfo()
+        );
+    }
 }
 
 ?>
\ No newline at end of file