fix(comments): Check comment object

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/56995/head
Joas Schilling 4 months ago
parent 255bea7a73
commit 41b75a6f41
No known key found for this signature in database
GPG Key ID: F72FA5B49FFA96B0
  1. 9
      apps/dav/lib/Comments/EntityCollection.php
  2. 23
      apps/dav/tests/unit/Comments/EntityCollectionTest.php
  3. 8
      lib/private/DB/QueryBuilder/QueryBuilder.php

@ -101,6 +101,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,
@ -154,8 +158,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;
}

@ -76,14 +76,16 @@ class EntityCollectionTest extends \Test\TestCase {
}
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 @@ class EntityCollectionTest extends \Test\TestCase {
}
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'));
}

@ -1108,6 +1108,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
@ -1125,6 +1129,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

Loading…
Cancel
Save