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:08:10 +0000 |
commit | 99b254bf312e292957495f157ea1e7977cf623f9 (patch) | |
tree | 1109aa9a02eb75be253abb748cb482bc2ce5b092 | |
parent | 0655eadd33b722eb047d88e032fac19381ec4d1d (diff) | |
download | nextcloud-server-backport/47425/stable29.tar.gz nextcloud-server-backport/47425/stable29.zip |
fix: Use getRelativePath method to check if node is inside folderbackport/47425/stable29
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 5485f049b2e..747960f3b10 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1215,7 +1215,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 2547bdec105..b021498d22e 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); |