Skip to content

Commit

Permalink
Fix wrong url on empty url (may happen with custom $_SERVER array)
Browse files Browse the repository at this point in the history
  • Loading branch information
BafS committed Oct 3, 2017
1 parent 0308297 commit 9db3715
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/Parvula/Parvula.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function __clone() {

/**
* Get core container
* Singleton pattern
*
* @return Pimple\Container
*/
Expand Down Expand Up @@ -55,6 +56,13 @@ public static function getRelativeURIToRoot($path = '') {
$postUrl = static::$request->getUri()->getPath();
$basePath = static::$request->getUri()->getBasePath();

$prefix = '';
// If no slash at root (should not happen normally), prefix with the current base path
if ($postUrl === '/' && substr(static::$request->getServerParam('PATH_INFO'), -1) !== '/') {
$token = explode('/', static::$request->getServerParam('PATH_INFO'));
$prefix = $token[count($token) - 1] . '/';
}

// Be sure to have a clean path
$postUrl = str_replace(['//', '///'], '/', $postUrl);

Expand All @@ -65,7 +73,7 @@ public static function getRelativeURIToRoot($path = '') {
++$slashNb;
}

return str_repeat('../', max($slashNb, 0)) . $path;
return $prefix . str_repeat('../', max($slashNb, 0)) . $path;
}

/**
Expand Down

0 comments on commit 9db3715

Please sign in to comment.