Skip to content

Commit 61dedd7

Browse files
Merge pull request #42524 from nextcloud/backport/42427/stable28
[stable28] fix(ViewController): Properly handle non-existent fileIds (regression lead to 500 errors)
2 parents 30f23a6 + 1f6f5fd commit 61dedd7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

apps/files/lib/Controller/ViewController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,16 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
237237
if ($fileid && $dir !== '') {
238238
$baseFolder = $this->rootFolder->getUserFolder($userId);
239239
$nodes = $baseFolder->getById((int) $fileid);
240-
$nodePath = $baseFolder->getRelativePath($nodes[0]->getPath());
241-
$relativePath = $nodePath ? dirname($nodePath) : '';
242-
// If the requested path does not contain the file id
243-
// or if the requested path is not the file id itself
244-
if (count($nodes) === 1 && $relativePath !== $dir && $nodePath !== $dir) {
245-
return $this->redirectToFile((int) $fileid);
240+
if (!empty($nodes)) {
241+
$nodePath = $baseFolder->getRelativePath($nodes[0]->getPath());
242+
$relativePath = $nodePath ? dirname($nodePath) : '';
243+
// If the requested path does not contain the file id
244+
// or if the requested path is not the file id itself
245+
if (count($nodes) === 1 && $relativePath !== $dir && $nodePath !== $dir) {
246+
return $this->redirectToFile((int) $fileid);
247+
}
248+
} else { // fileid does not exist anywhere
249+
$fileNotFound = true;
246250
}
247251
}
248252

0 commit comments

Comments
 (0)