aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/Share20/Manager.php3
-rw-r--r--tests/lib/Share20/ManagerTest.php24
2 files changed, 16 insertions, 11 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 5730f4f9635..4856c051307 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -1093,7 +1093,8 @@ class Manager implements IManager {
/* Ignore share of non-existing node */
continue;
}
- if (str_starts_with($path, $node->getPath() . '/') || ($path === $node->getPath())) {
+ if ($node->getRelativePath($path) !== null) {
+ /* If relative path is not null it means the shared node is the same or in a subfolder */
$reshareRecords[] = $share;
}
}
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index c739e2e8851..a4c1dd3803d 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -9,6 +9,7 @@ namespace Test\Share20;
use DateTimeZone;
use OC\Files\Mount\MoveableMount;
+use OC\Files\Utils\PathHelper;
use OC\KnownUser\KnownUserService;
use OC\Share20\DefaultShareProvider;
use OC\Share20\Exception;
@@ -199,6 +200,14 @@ class ManagerTest extends \Test\TestCase {
]);
}
+ private function createFolderMock(string $folderPath): MockObject&Folder {
+ $folder = $this->createMock(Folder::class);
+ $folder->method('getPath')->willReturn($folderPath);
+ $folder->method('getRelativePath')->willReturnCallback(
+ fn (string $path): ?string => PathHelper::getRelativePath($folderPath, $path)
+ );
+ return $folder;
+ }
public function testDeleteNoShareId(): void {
$this->expectException(\InvalidArgumentException::class);
@@ -514,14 +523,11 @@ class ManagerTest extends \Test\TestCase {
->setMethods(['updateShare', 'getSharesInFolder', 'generalCreateChecks'])
->getMock();
- $folder = $this->createMock(Folder::class);
- $folder->method('getPath')->willReturn('/path/to/folder');
+ $folder = $this->createFolderMock('/path/to/folder');
- $subFolder = $this->createMock(Folder::class);
- $subFolder->method('getPath')->willReturn('/path/to/folder/sub');
+ $subFolder = $this->createFolderMock('/path/to/folder/sub');
- $otherFolder = $this->createMock(Folder::class);
- $otherFolder->method('getPath')->willReturn('/path/to/otherfolder/');
+ $otherFolder = $this->createFolderMock('/path/to/otherfolder/');
$share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(IShare::TYPE_USER);
@@ -567,8 +573,7 @@ class ManagerTest extends \Test\TestCase {
->setMethods(['updateShare', 'getSharesInFolder', 'getSharedWith', 'generalCreateChecks'])
->getMock();
- $folder = $this->createMock(Folder::class);
- $folder->method('getPath')->willReturn('/path/to/folder');
+ $folder = $this->createFolderMock('/path/to/folder');
$share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(IShare::TYPE_USER);
@@ -596,8 +601,7 @@ class ManagerTest extends \Test\TestCase {
->setMethods(['updateShare', 'getSharesInFolder', 'getSharedWith', 'generalCreateChecks'])
->getMock();
- $folder = $this->createMock(Folder::class);
- $folder->method('getPath')->willReturn('/path/to/folder');
+ $folder = $this->createFolderMock('/path/to/folder');
$userA = $this->createMock(IUser::class);
$userA->method('getUID')->willReturn('userA');