Skip to content

Commit

Permalink
fix(dav): Verify target path in setName instead of source path
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jul 15, 2024
1 parent fe08292 commit abc3227
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public function setName($name) {

[$parentPath,] = \Sabre\Uri\split($this->path);
[, $newName] = \Sabre\Uri\split($name);
$newPath = $parentPath . '/' . $newName;

// verify path of the target
$this->verifyPath();
$this->verifyPath($newPath);

$newPath = $parentPath . '/' . $newName;

if (!$this->fileView->rename($this->path, $newPath)) {
throw new \Sabre\DAV\Exception('Failed to rename '. $this->path . ' to ' . $newPath);
Expand Down Expand Up @@ -355,10 +355,13 @@ public function getOwner() {
return $this->info->getOwner();
}

protected function verifyPath() {
protected function verifyPath(?string $path = null) {

Check notice

Code scanning / Psalm

MissingReturnType Note

Method OCA\DAV\Connector\Sabre\Node::verifyPath does not have a return type, expecting void
try {
$fileName = basename($this->info->getPath());
$this->fileView->verifyPath($this->path, $fileName);
$path = $path ?? $this->info->getPath();
$this->fileView->verifyPath(
dirname($path),
basename($path),
);
} catch (\OCP\Files\InvalidPathException $ex) {
throw new InvalidPath($ex->getMessage());
}
Expand Down

0 comments on commit abc3227

Please sign in to comment.