Skip to content

Commit 5d5cbbf

Browse files
authored
Merge pull request #56984 from nextcloud/backport/56982/stable31
[stable31] fix(comments): Check comment object
2 parents 1f9687f + 0caff48 commit 5d5cbbf

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

apps/dav/lib/Comments/EntityCollection.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public function getId() {
7777
public function getChild($name) {
7878
try {
7979
$comment = $this->commentsManager->get($name);
80+
if ($comment->getObjectType() !== $this->name
81+
|| $comment->getObjectId() !== $this->id) {
82+
throw new NotFound();
83+
}
8084
return new CommentNode(
8185
$this->commentsManager,
8286
$comment,
@@ -130,8 +134,9 @@ public function findChildren($limit = 0, $offset = 0, ?\DateTime $datetime = nul
130134
*/
131135
public function childExists($name) {
132136
try {
133-
$this->commentsManager->get($name);
134-
return true;
137+
$comment = $this->commentsManager->get($name);
138+
return $comment->getObjectType() === $this->name
139+
&& $comment->getObjectId() === $this->id;
135140
} catch (NotFoundException $e) {
136141
return false;
137142
}

apps/dav/tests/unit/Comments/EntityCollectionTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ public function testGetId(): void {
6060
}
6161

6262
public function testGetChild(): void {
63+
$comment = $this->createMock(IComment::class);
64+
$comment->method('getObjectType')
65+
->willReturn('files');
66+
$comment->method('getObjectId')
67+
->willReturn('19');
68+
6369
$this->commentsManager->expects($this->once())
6470
->method('get')
6571
->with('55')
66-
->willReturn(
67-
$this->getMockBuilder(IComment::class)
68-
->disableOriginalConstructor()
69-
->getMock()
70-
);
72+
->willReturn($comment);
7173

7274
$node = $this->collection->getChild('55');
7375
$this->assertTrue($node instanceof CommentNode);
@@ -119,6 +121,17 @@ public function testFindChildren(): void {
119121
}
120122

121123
public function testChildExistsTrue(): void {
124+
$comment = $this->createMock(IComment::class);
125+
$comment->method('getObjectType')
126+
->willReturn('files');
127+
$comment->method('getObjectId')
128+
->willReturn('19');
129+
130+
$this->commentsManager->expects($this->once())
131+
->method('get')
132+
->with('44')
133+
->willReturn($comment);
134+
122135
$this->assertTrue($this->collection->childExists('44'));
123136
}
124137

lib/private/DB/QueryBuilder/QueryBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,10 @@ public function orHaving(...$having) {
11171117
* @return $this This QueryBuilder instance.
11181118
*/
11191119
public function orderBy($sort, $order = null) {
1120+
if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) {
1121+
$order = null;
1122+
}
1123+
11201124
$this->queryBuilder->orderBy(
11211125
$this->helper->quoteColumnName($sort),
11221126
$order
@@ -1134,6 +1138,10 @@ public function orderBy($sort, $order = null) {
11341138
* @return $this This QueryBuilder instance.
11351139
*/
11361140
public function addOrderBy($sort, $order = null) {
1141+
if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) {
1142+
$order = null;
1143+
}
1144+
11371145
$this->queryBuilder->addOrderBy(
11381146
$this->helper->quoteColumnName($sort),
11391147
$order

lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,21 @@ public function setFirstResult($firstResult) {
276276
}
277277

278278
public function addOrderBy($sort, $order = null) {
279-
$this->registerOrder((string)$sort, (string)$order ?? 'ASC');
279+
if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) {
280+
$order = null;
281+
}
282+
283+
$this->registerOrder((string)$sort, (string)($order ?? 'ASC'));
280284
return parent::addOrderBy($sort, $order);
281285
}
282286

283287
public function orderBy($sort, $order = null) {
288+
if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) {
289+
$order = null;
290+
}
291+
284292
$this->sortList = [];
285-
$this->registerOrder((string)$sort, (string)$order ?? 'ASC');
293+
$this->registerOrder((string)$sort, (string)($order ?? 'ASC'));
286294
return parent::orderBy($sort, $order);
287295
}
288296

0 commit comments

Comments
 (0)