Skip to content
Snippets Groups Projects
Unverified Commit e00f6ad8 authored by Ferdinand Thiessen's avatar Ferdinand Thiessen
Browse files

fix(dav): Verify target path in `setName` instead of source path

parent 4bb593b4
No related branches found
No related tags found
No related merge requests found
...@@ -122,11 +122,11 @@ abstract class Node implements \Sabre\DAV\INode { ...@@ -122,11 +122,11 @@ abstract class Node implements \Sabre\DAV\INode {
[$parentPath,] = \Sabre\Uri\split($this->path); [$parentPath,] = \Sabre\Uri\split($this->path);
[, $newName] = \Sabre\Uri\split($name); [, $newName] = \Sabre\Uri\split($name);
$newPath = $parentPath . '/' . $newName;
// verify path of the target // verify path of the target
$this->verifyPath(); $this->verifyPath($newPath);
$newPath = $parentPath . '/' . $newName;
if (!$this->fileView->rename($this->path, $newPath)) { if (!$this->fileView->rename($this->path, $newPath)) {
throw new \Sabre\DAV\Exception('Failed to rename '. $this->path . ' to ' . $newPath); throw new \Sabre\DAV\Exception('Failed to rename '. $this->path . ' to ' . $newPath);
...@@ -355,10 +355,13 @@ abstract class Node implements \Sabre\DAV\INode { ...@@ -355,10 +355,13 @@ abstract class Node implements \Sabre\DAV\INode {
return $this->info->getOwner(); return $this->info->getOwner();
} }
protected function verifyPath() { protected function verifyPath(?string $path = null): void {
try { try {
$fileName = basename($this->info->getPath()); $path = $path ?? $this->info->getPath();
$this->fileView->verifyPath($this->path, $fileName); $this->fileView->verifyPath(
dirname($path),
basename($path),
);
} catch (\OCP\Files\InvalidPathException $ex) { } catch (\OCP\Files\InvalidPathException $ex) {
throw new InvalidPath($ex->getMessage()); throw new InvalidPath($ex->getMessage());
} }
......
...@@ -397,7 +397,7 @@ class DirectoryTest extends \Test\TestCase { ...@@ -397,7 +397,7 @@ class DirectoryTest extends \Test\TestCase {
public function moveFailedInvalidCharsProvider() { public function moveFailedInvalidCharsProvider() {
return [ 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], []],
]; ];
} }
...@@ -463,7 +463,7 @@ class DirectoryTest extends \Test\TestCase { ...@@ -463,7 +463,7 @@ class DirectoryTest extends \Test\TestCase {
$sourceNode = new Directory($view, $sourceInfo); $sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class) $targetNode = $this->getMockBuilder(Directory::class)
->setMethods(['childExists']) ->onlyMethods(['childExists'])
->setConstructorArgs([$view, $targetInfo]) ->setConstructorArgs([$view, $targetInfo])
->getMock(); ->getMock();
$targetNode->expects($this->once())->method('childExists') $targetNode->expects($this->once())->method('childExists')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment