Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/dav/lib/Comments/EntityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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,
Expand Down Expand Up @@ -137,8 +141,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;
}
Expand Down
23 changes: 18 additions & 5 deletions apps/dav/tests/unit/Comments/EntityCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,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 \OCA\DAV\Comments\CommentNode);
Expand Down Expand Up @@ -117,6 +119,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'));
}

Expand Down
8 changes: 8 additions & 0 deletions lib/private/DB/QueryBuilder/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading