diff --git a/apps/dav/lib/Comments/EntityCollection.php b/apps/dav/lib/Comments/EntityCollection.php index 2581ff0c367..b598544cdcb 100644 --- a/apps/dav/lib/Comments/EntityCollection.php +++ b/apps/dav/lib/Comments/EntityCollection.php @@ -100,6 +100,10 @@ class EntityCollection extends RootCollection implements IProperties { 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, @@ -153,8 +157,9 @@ class EntityCollection extends RootCollection implements IProperties { */ 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 ec98441d252..1bef3e0507c 100644 --- a/apps/dav/tests/unit/Comments/EntityCollectionTest.php +++ b/apps/dav/tests/unit/Comments/EntityCollectionTest.php @@ -76,14 +76,16 @@ class EntityCollectionTest extends \Test\TestCase { } 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 \OCA\DAV\Comments\CommentNode); @@ -135,6 +137,17 @@ class EntityCollectionTest extends \Test\TestCase { } 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 d78cf50e319..26c8fe9a519 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -1103,6 +1103,10 @@ class QueryBuilder implements IQueryBuilder { * @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 @@ -1120,6 +1124,10 @@ class QueryBuilder implements IQueryBuilder { * @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