mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(comments): Check comment object
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
0fd888da09
commit
69e6b6a483
4 changed files with 43 additions and 9 deletions
|
|
@ -77,6 +77,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,
|
||||
|
|
@ -130,8 +134,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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,14 +48,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->assertInstanceOf(CommentNode::class, $node);
|
||||
|
|
@ -107,6 +109,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'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1094,6 +1094,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
|
||||
|
|
@ -1111,6 +1115,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
|
||||
|
|
|
|||
|
|
@ -280,13 +280,21 @@ class ShardedQueryBuilder extends ExtendedQueryBuilder {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue