From: Josh Richards Date: Thu, 21 Dec 2023 16:19:06 +0000 (-0500) Subject: fix(ViewController): Regression lead to 500 on non-existent fileIds X-Git-Tag: v29.0.0beta1~574^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F42427%2Fhead;p=nextcloud-server.git fix(ViewController): Regression lead to 500 on non-existent fileIds Fixes #42418 Signed-off-by: Josh Richards --- diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index be5069b7f61..8de679f25dd 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -237,12 +237,16 @@ class ViewController extends Controller { if ($fileid && $dir !== '') { $baseFolder = $this->rootFolder->getUserFolder($userId); $nodes = $baseFolder->getById((int) $fileid); - $nodePath = $baseFolder->getRelativePath($nodes[0]->getPath()); - $relativePath = $nodePath ? dirname($nodePath) : ''; - // If the requested path does not contain the file id - // or if the requested path is not the file id itself - if (count($nodes) === 1 && $relativePath !== $dir && $nodePath !== $dir) { - return $this->redirectToFile((int) $fileid); + if (!empty($nodes)) { + $nodePath = $baseFolder->getRelativePath($nodes[0]->getPath()); + $relativePath = $nodePath ? dirname($nodePath) : ''; + // If the requested path does not contain the file id + // or if the requested path is not the file id itself + if (count($nodes) === 1 && $relativePath !== $dir && $nodePath !== $dir) { + return $this->redirectToFile((int) $fileid); + } + } else { // fileid does not exist anywhere + $fileNotFound = true; } }