Skip to content

Commit 9db3715

Browse files
committed
Fix wrong url on empty url (may happen with custom $_SERVER array)
1 parent 0308297 commit 9db3715

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/Parvula/Parvula.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function __clone() {
2626

2727
/**
2828
* Get core container
29+
* Singleton pattern
2930
*
3031
* @return Pimple\Container
3132
*/
@@ -55,6 +56,13 @@ public static function getRelativeURIToRoot($path = '') {
5556
$postUrl = static::$request->getUri()->getPath();
5657
$basePath = static::$request->getUri()->getBasePath();
5758

59+
$prefix = '';
60+
// If no slash at root (should not happen normally), prefix with the current base path
61+
if ($postUrl === '/' && substr(static::$request->getServerParam('PATH_INFO'), -1) !== '/') {
62+
$token = explode('/', static::$request->getServerParam('PATH_INFO'));
63+
$prefix = $token[count($token) - 1] . '/';
64+
}
65+
5866
// Be sure to have a clean path
5967
$postUrl = str_replace(['//', '///'], '/', $postUrl);
6068

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

68-
return str_repeat('../', max($slashNb, 0)) . $path;
76+
return $prefix . str_repeat('../', max($slashNb, 0)) . $path;
6977
}
7078

7179
/**

0 commit comments

Comments
 (0)