public: fix extra slash in path (fix #716)

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/803/head
Varun Patil 2023-08-30 13:25:28 -07:00
parent 77a557547e
commit 4122f592b6
2 changed files with 5 additions and 4 deletions

View File

@ -196,9 +196,10 @@ class PublicController extends AuthPublicShareController
$relPath = substr($node->getPath(), \strlen($userFolder->getPath()));
// Get the user's folders path
$foldersPath = $this->config->getUserValue($user->getUID(), Application::APPNAME, 'foldersPath', '');
$foldersPath = $foldersPath ?: '/';
$foldersPath = Util::sanitizePath($foldersPath);
$foldersPath = $this->config->getUserValue($user->getUID(), Application::APPNAME, 'foldersPath', null) ?: '/';
// Sanitize folders path ensuring leading and trailing slashes
$foldersPath = Util::sanitizePath('/' . $foldersPath . '/');
// Check if relPath starts with foldersPath
if (0 !== strpos($relPath, $foldersPath)) {

View File

@ -324,7 +324,7 @@ class Util
/**
* Sanitize a path to keep only ASCII characters and special characters.
*/
public static function sanitizePath(string $path)
public static function sanitizePath(string $path): string
{
$path = str_replace("\0", '', $path); // remove null characters