aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Richards <josh.t.richards@gmail.com>2023-12-21 11:19:06 -0500
committerGitHub <noreply@github.com>2023-12-21 11:19:06 -0500
commita66877813c4cf20088e81b3b847742fa2e210f3d (patch)
treef00d41897e1547483cea3b120cee7d95f06d5793
parent6e7c0906f6a10ba961359bfb20205caeefdfdcff (diff)
downloadnextcloud-server-a66877813c4cf20088e81b3b847742fa2e210f3d.tar.gz
nextcloud-server-a66877813c4cf20088e81b3b847742fa2e210f3d.zip
fix(ViewController): Regression lead to 500 on non-existent fileIds
Fixes #42418 Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
-rw-r--r--apps/files/lib/Controller/ViewController.php16
1 files changed, 10 insertions, 6 deletions
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;
}
}