diff --git a/apps/dav/lib/Comments/EntityCollection.php b/apps/dav/lib/Comments/EntityCollection.php index 33c58ee44d288..fadb5f5dabd12 100644 --- a/apps/dav/lib/Comments/EntityCollection.php +++ b/apps/dav/lib/Comments/EntityCollection.php @@ -77,6 +77,10 @@ public function getId() { public function getChild($name) { try { $comment = $this->commentsManager->get($name); + if ($comment->getObjectType() !== $this->name + || $comment->getObjectId() !== $this->id) { + throw new NotFound(); + } return new CommentNode( $this->commentsManager, $comment, @@ -130,8 +134,9 @@ public function findChildren($limit = 0, $offset = 0, ?\DateTime $datetime = nul */ public function childExists($name) { try { - $this->commentsManager->get($name); - return true; + $comment = $this->commentsManager->get($name); + return $comment->getObjectType() === $this->name + && $comment->getObjectId() === $this->id; } catch (NotFoundException $e) { return false; } diff --git a/apps/dav/tests/unit/Comments/EntityCollectionTest.php b/apps/dav/tests/unit/Comments/EntityCollectionTest.php index e5a68e5a72684..ea7c61e5a707a 100644 --- a/apps/dav/tests/unit/Comments/EntityCollectionTest.php +++ b/apps/dav/tests/unit/Comments/EntityCollectionTest.php @@ -60,14 +60,16 @@ public function testGetId(): void { } public function testGetChild(): void { + $comment = $this->createMock(IComment::class); + $comment->method('getObjectType') + ->willReturn('files'); + $comment->method('getObjectId') + ->willReturn('19'); + $this->commentsManager->expects($this->once()) ->method('get') ->with('55') - ->willReturn( - $this->getMockBuilder(IComment::class) - ->disableOriginalConstructor() - ->getMock() - ); + ->willReturn($comment); $node = $this->collection->getChild('55'); $this->assertTrue($node instanceof CommentNode); @@ -119,6 +121,17 @@ public function testFindChildren(): void { } public function testChildExistsTrue(): void { + $comment = $this->createMock(IComment::class); + $comment->method('getObjectType') + ->willReturn('files'); + $comment->method('getObjectId') + ->willReturn('19'); + + $this->commentsManager->expects($this->once()) + ->method('get') + ->with('44') + ->willReturn($comment); + $this->assertTrue($this->collection->childExists('44')); } diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index 640959c05c660..ef6d9360ebc34 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -1117,6 +1117,10 @@ public function orHaving(...$having) { * @return $this This QueryBuilder instance. */ public function orderBy($sort, $order = null) { + if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) { + $order = null; + } + $this->queryBuilder->orderBy( $this->helper->quoteColumnName($sort), $order @@ -1134,6 +1138,10 @@ public function orderBy($sort, $order = null) { * @return $this This QueryBuilder instance. */ public function addOrderBy($sort, $order = null) { + if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) { + $order = null; + } + $this->queryBuilder->addOrderBy( $this->helper->quoteColumnName($sort), $order diff --git a/lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php b/lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php index 04082f76ae891..b6e5e7f354edc 100644 --- a/lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php +++ b/lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php @@ -276,13 +276,21 @@ public function setFirstResult($firstResult) { } public function addOrderBy($sort, $order = null) { - $this->registerOrder((string)$sort, (string)$order ?? 'ASC'); + if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) { + $order = null; + } + + $this->registerOrder((string)$sort, (string)($order ?? 'ASC')); return parent::addOrderBy($sort, $order); } public function orderBy($sort, $order = null) { + if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) { + $order = null; + } + $this->sortList = []; - $this->registerOrder((string)$sort, (string)$order ?? 'ASC'); + $this->registerOrder((string)$sort, (string)($order ?? 'ASC')); return parent::orderBy($sort, $order); }