diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-10-14 17:23:29 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-12-03 15:06:38 +0000 |
commit | 11954e81197258401a8a21cf8e562c622c299229 (patch) | |
tree | bde36e872aa3d8df3a76abd56a8fb08b6c71c760 | |
parent | 15c138e0860f868bebbdc159c2a0e66b6c8fe63f (diff) | |
download | nextcloud-server-backport/47425/stable28.tar.gz nextcloud-server-backport/47425/stable28.zip |
fix: Use getRelativePath method to check if node is inside folderbackport/47425/stable28
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
[skip ci]
-rw-r--r-- | lib/private/Share20/Manager.php | 3 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 86948bb78a9..648ffcf266f 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1207,7 +1207,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 485e57d69bd..c25a6b02c43 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -23,6 +23,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; @@ -213,6 +214,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() { $this->expectException(\InvalidArgumentException::class); |