diff --git a/src/Http/RequestFactory.php b/src/Http/RequestFactory.php index 6ada3696..785659ad 100644 --- a/src/Http/RequestFactory.php +++ b/src/Http/RequestFactory.php @@ -113,15 +113,15 @@ public function createHttpRequest() $script = '/'; } - $path = strtolower($url->getPath()) . '/'; - $script = strtolower($script) . '/'; + $path = $url->getPath(); $max = min(strlen($path), strlen($script)); - for ($i = 0; $i < $max; $i++) { - if ($path[$i] !== $script[$i]) { - break; - } elseif ($path[$i] === '/') { - $url->setScriptPath(substr($url->getPath(), 0, $i + 1)); - } + for ($i = 0; $i < $max && $path[$i] === $script[$i]; $i++) { + // nothing + } + if ($i === $max && strlen($path) === strlen($script)) { + $url->setScriptPath($path); + } else { + $url->setScriptPath(substr($path, 0, strrpos($path, '/', $i - $max - 1) + 1)); } // GET, POST, COOKIE diff --git a/tests/Http/RequestFactory.scriptPath.phpt b/tests/Http/RequestFactory.scriptPath.phpt index 2a43a0a0..c17b75a8 100644 --- a/tests/Http/RequestFactory.scriptPath.phpt +++ b/tests/Http/RequestFactory.scriptPath.phpt @@ -16,7 +16,7 @@ $factory = new RequestFactory; test(function() use ($factory) { $_SERVER = array( 'REQUEST_URI' => '/projects/modules-usage/www/', - 'SCRIPT_FILENAME' => 'W:/projects/Modules-Usage/www/index.php', + 'SCRIPT_FILENAME' => 'W:/projects/modules-usage/www/index.php', 'SCRIPT_NAME' => '/projects/modules-usage/www/index.php', ); @@ -27,8 +27,8 @@ test(function() use ($factory) { test(function() use ($factory) { $_SERVER = array( 'REQUEST_URI' => '/projects/modules-usage/www/default/add-item', - 'SCRIPT_FILENAME' => 'W:/projects/Modules-Usage/www/index.php', - 'SCRIPT_NAME' => '/projects/Modules-Usage/www/index.php', + 'SCRIPT_FILENAME' => 'W:/projects/modules-usage/www/index.php', + 'SCRIPT_NAME' => '/projects/modules-usage/www/index.php', ); Assert::same( '/projects/modules-usage/www/', $factory->createHttpRequest()->getUrl()->getScriptPath() ); @@ -55,3 +55,55 @@ test(function() use ($factory) { Assert::same( '/www/', $factory->createHttpRequest()->getUrl()->getScriptPath() ); }); + + +test(function() use ($factory) { + $_SERVER = array( + 'REQUEST_URI' => '/test/in', + 'SCRIPT_NAME' => '/test/index.php', + ); + + Assert::same( '/test/', $factory->createHttpRequest()->getUrl()->getScriptPath() ); +}); + + +test(function() use ($factory) { + $_SERVER = array( + 'REQUEST_URI' => '/test//', + 'SCRIPT_NAME' => '/test/index.php', + ); + + Assert::same( '/test/', $factory->createHttpRequest()->getUrl()->getScriptPath() ); +}); + + +// http://forum.nette.org/cs/5932-lepsi-detekce-requesturi-a-scriptpath +test(function() use ($factory) { + $_SERVER = array( + 'REQUEST_URI' => '/sign/in/', + 'SCRIPT_NAME' => '/sign/in/', + ); + + Assert::same( '/sign/in/', $factory->createHttpRequest()->getUrl()->getScriptPath() ); +}); + + +// http://forum.nette.org/cs/9139-spatny-urlscript-scriptpath +test(function() use ($factory) { + $_SERVER = array( + 'REQUEST_URI' => '/configuration/', + 'SCRIPT_NAME' => '/configuration/www/index.php', + ); + + Assert::same( '/configuration/', $factory->createHttpRequest()->getUrl()->getScriptPath() ); +}); + + +test(function() use ($factory) { + $_SERVER = array( + 'REQUEST_URI' => '/blog/WWW/', + 'SCRIPT_NAME' => '/blog/www/index.php', + ); + + Assert::same( '/blog/', $factory->createHttpRequest()->getUrl()->getScriptPath() ); +});