diff --git a/apps/dav/lib/Comments/EntityCollection.php b/apps/dav/lib/Comments/EntityCollection.php index d9b06e1240c70..cb7556a67ff48 100644 --- a/apps/dav/lib/Comments/EntityCollection.php +++ b/apps/dav/lib/Comments/EntityCollection.php @@ -101,6 +101,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, @@ -154,8 +158,9 @@ public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null */ 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 4466b0a63074b..9ff75b18fe279 100644 --- a/apps/dav/tests/unit/Comments/EntityCollectionTest.php +++ b/apps/dav/tests/unit/Comments/EntityCollectionTest.php @@ -76,14 +76,16 @@ public function testGetId() { } public function testGetChild() { + $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 \OCA\DAV\Comments\CommentNode); @@ -135,6 +137,17 @@ public function testFindChildren() { } public function testChildExistsTrue() { + $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 bf5ec2f6bec91..2527b8ddb045c 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -1108,6 +1108,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 @@ -1125,6 +1129,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