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 4bb593b commit e00f6ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 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): 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
4 changes: 2 additions & 2 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public function testMoveFailedInvalidChars($source, $destination, $updatables, $

public function moveFailedInvalidCharsProvider() {
return [
['a/b', 'a/*', ['a' => true, 'a/b' => true, 'a/c*' => false], []],
['a/valid', "a/i\nvalid", ['a' => true, 'a/valid' => true, 'a/c*' => false], []],
];
}

Expand Down Expand Up @@ -463,7 +463,7 @@ public function testFailingMove(): void {

$sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class)
->setMethods(['childExists'])
->onlyMethods(['childExists'])
->setConstructorArgs([$view, $targetInfo])
->getMock();
$targetNode->expects($this->once())->method('childExists')
Expand Down

0 comments on commit e00f6ad

Please sign in to comment.