Skip to content

Commit 97800c5

Browse files
come-ncbackportbot[bot]
authored andcommitted
fix: Use getRelativePath method to check if node is inside folder
Signed-off-by: Côme Chilliet <[email protected]>
1 parent e1a23cf commit 97800c5

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/private/Share20/Manager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,8 @@ protected function promoteReshares(IShare $share): void {
12161216
/* Ignore share of non-existing node */
12171217
continue;
12181218
}
1219-
if (str_starts_with($path, $node->getPath() . '/') || ($path === $node->getPath())) {
1219+
if ($node->getRelativePath($path) !== null) {
1220+
/* If relative path is not null it means the shared node is the same or in a subfolder */
12201221
$reshareRecords[] = $share;
12211222
}
12221223
}

tests/lib/Share20/ManagerTest.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use DateTimeZone;
2525
use OC\Files\Mount\MoveableMount;
26+
use OC\Files\Utils\PathHelper;
2627
use OC\KnownUser\KnownUserService;
2728
use OC\Share20\DefaultShareProvider;
2829
use OC\Share20\Exception;
@@ -213,6 +214,14 @@ private function createManagerMock() {
213214
]);
214215
}
215216

217+
private function createFolderMock(string $folderPath): MockObject&Folder {
218+
$folder = $this->createMock(Folder::class);
219+
$folder->method('getPath')->willReturn($folderPath);
220+
$folder->method('getRelativePath')->willReturnCallback(
221+
fn (string $path): ?string => PathHelper::getRelativePath($folderPath, $path)
222+
);
223+
return $folder;
224+
}
216225

217226
public function testDeleteNoShareId() {
218227
$this->expectException(\InvalidArgumentException::class);
@@ -528,14 +537,11 @@ public function testPromoteReshare(): void {
528537
->setMethods(['updateShare', 'getSharesInFolder', 'generalCreateChecks'])
529538
->getMock();
530539

531-
$folder = $this->createMock(Folder::class);
532-
$folder->method('getPath')->willReturn('/path/to/folder');
540+
$folder = $this->createFolderMock('/path/to/folder');
533541

534-
$subFolder = $this->createMock(Folder::class);
535-
$subFolder->method('getPath')->willReturn('/path/to/folder/sub');
542+
$subFolder = $this->createFolderMock('/path/to/folder/sub');
536543

537-
$otherFolder = $this->createMock(Folder::class);
538-
$otherFolder->method('getPath')->willReturn('/path/to/otherfolder/');
544+
$otherFolder = $this->createFolderMock('/path/to/otherfolder/');
539545

540546
$share = $this->createMock(IShare::class);
541547
$share->method('getShareType')->willReturn(IShare::TYPE_USER);
@@ -581,8 +587,7 @@ public function testPromoteReshareWhenUserHasAnotherShare(): void {
581587
->setMethods(['updateShare', 'getSharesInFolder', 'getSharedWith', 'generalCreateChecks'])
582588
->getMock();
583589

584-
$folder = $this->createMock(Folder::class);
585-
$folder->method('getPath')->willReturn('/path/to/folder');
590+
$folder = $this->createFolderMock('/path/to/folder');
586591

587592
$share = $this->createMock(IShare::class);
588593
$share->method('getShareType')->willReturn(IShare::TYPE_USER);
@@ -610,8 +615,7 @@ public function testPromoteReshareOfUsersInGroupShare(): void {
610615
->setMethods(['updateShare', 'getSharesInFolder', 'getSharedWith', 'generalCreateChecks'])
611616
->getMock();
612617

613-
$folder = $this->createMock(Folder::class);
614-
$folder->method('getPath')->willReturn('/path/to/folder');
618+
$folder = $this->createFolderMock('/path/to/folder');
615619

616620
$userA = $this->createMock(IUser::class);
617621
$userA->method('getUID')->willReturn('userA');

0 commit comments

Comments
 (0)