]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(share): Return empty string if no label is set backport/48673/stable29 48704/head
authorFerdinand Thiessen <opensource@fthiessen.de>
Sat, 12 Oct 2024 15:51:56 +0000 (17:51 +0200)
committerFerdinand Thiessen <opensource@fthiessen.de>
Tue, 15 Oct 2024 14:56:59 +0000 (16:56 +0200)
* Resolves: https://github.com/nextcloud/server/issues/48629

While the database supports NULL, the typing has always said it only returns *string*.
So to not break any apps that might trust the typings we should return `''` if the database is set to `NULL`.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
lib/private/Share20/DefaultShareProvider.php
tests/lib/Share20/DefaultShareProviderTest.php

index fe13e336712e7550ce2fabee0a876630afdd5507..ffe7190160460ff0aa0f58c7cae6cb8a052ea022 100644 (file)
@@ -1057,7 +1057,7 @@ class DefaultShareProvider implements IShareProvider {
                                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
                                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
                        ))
-                       ->execute();
+                       ->executeQuery();
 
                $data = $cursor->fetch();
 
@@ -1090,7 +1090,7 @@ class DefaultShareProvider implements IShareProvider {
                        ->setNote((string)$data['note'])
                        ->setMailSend((bool)$data['mail_send'])
                        ->setStatus((int)$data['accepted'])
-                       ->setLabel($data['label']);
+                       ->setLabel($data['label'] ?? '');
 
                $shareTime = new \DateTime();
                $shareTime->setTimestamp((int)$data['stime']);
index d7d13b27f1284be888d99dff25580944b6e83e8b..f578bc313aac8b892f5bcdcd313b9e4ef6c40ae5 100644 (file)
@@ -891,6 +891,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
                                'file_target' => $qb->expr()->literal('myTarget'),
                                'permissions' => $qb->expr()->literal(13),
                                'token' => $qb->expr()->literal('secrettoken'),
+                               'label' => $qb->expr()->literal('the label'),
                        ]);
                $qb->execute();
                $id = $qb->getLastInsertId();
@@ -906,10 +907,43 @@ class DefaultShareProviderTest extends \Test\TestCase {
                $this->assertSame('sharedBy', $share->getSharedBy());
                $this->assertSame('secrettoken', $share->getToken());
                $this->assertSame('password', $share->getPassword());
+               $this->assertSame('the label', $share->getLabel());
                $this->assertSame(true, $share->getSendPasswordByTalk());
                $this->assertSame(null, $share->getSharedWith());
        }
 
+       /**
+        * Assert that if no label is provided the label is correctly,
+        * as types on IShare, a string and not null
+        */
+       public function testGetShareByTokenNullLabel(): void {
+               $qb = $this->dbConn->getQueryBuilder();
+
+               $qb->insert('share')
+                       ->values([
+                               'share_type' => $qb->expr()->literal(IShare::TYPE_LINK),
+                               'password' => $qb->expr()->literal('password'),
+                               'password_by_talk' => $qb->expr()->literal(true),
+                               'uid_owner' => $qb->expr()->literal('shareOwner'),
+                               'uid_initiator' => $qb->expr()->literal('sharedBy'),
+                               'item_type' => $qb->expr()->literal('file'),
+                               'file_source' => $qb->expr()->literal(42),
+                               'file_target' => $qb->expr()->literal('myTarget'),
+                               'permissions' => $qb->expr()->literal(13),
+                               'token' => $qb->expr()->literal('secrettoken'),
+                       ]);
+               $qb->executeStatement();
+               $id = $qb->getLastInsertId();
+
+               $file = $this->createMock(File::class);
+
+               $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
+               $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file);
+
+               $share = $this->provider->getShareByToken('secrettoken');
+               $this->assertEquals($id, $share->getId());
+               $this->assertSame('', $share->getLabel());
+       }
 
        public function testGetShareByTokenNotFound() {
                $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);