N°6061 - allow local path from an arbitrary path

This commit is contained in:
Eric Espie
2023-07-27 12:06:14 +02:00
parent aa6fa4c674
commit fb23bddeb2

View File

@@ -2651,20 +2651,21 @@ SQL;
* Dir separator is changed to '/' for consistency among the different OS
*
* @param string $sAbsolutePath absolute path
* @param string $sBasePath
*
* @return false|string
*/
final public static function LocalPath($sAbsolutePath)
final public static function LocalPath(string $sAbsolutePath, string $sBasePath = APPROOT)
{
$sRootPath = realpath(APPROOT);
$sRootPath = realpath($sBasePath);
$sFullPath = realpath($sAbsolutePath);
if (($sFullPath === false) || !self::StartsWith($sFullPath, $sRootPath))
{
return false;
}
$sLocalPath = substr($sFullPath, strlen($sRootPath.DIRECTORY_SEPARATOR));
$sLocalPath = str_replace(DIRECTORY_SEPARATOR, '/', $sLocalPath);
return $sLocalPath;
return str_replace(DIRECTORY_SEPARATOR, '/', $sLocalPath);
}
/**