]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(ViewController): Regression lead to 500 on non-existent fileIds 42524/head
authorJosh Richards <josh.t.richards@gmail.com>
Thu, 21 Dec 2023 16:19:06 +0000 (11:19 -0500)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Fri, 29 Dec 2023 13:48:00 +0000 (13:48 +0000)
Fixes #42418

Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
apps/files/lib/Controller/ViewController.php

index be5069b7f612dcb511eced333aee220e6fb5c8c1..8de679f25ddd040fe8447e85d26b4cd4dcaebfa1 100644 (file)
@@ -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;
                        }
                }