Skip to content

Commit 69e6b6a

Browse files
committed
fix(comments): Check comment object
Signed-off-by: Joas Schilling <[email protected]>
1 parent 0fd888d commit 69e6b6a

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
@@ -48,14 +48,16 @@ public function testGetId(): void {
4848
}
4949

5050
public function testGetChild(): void {
51+
$comment = $this->createMock(IComment::class);
52+
$comment->method('getObjectType')
53+
->willReturn('files');
54+
$comment->method('getObjectId')
55+
->willReturn('19');
56+
5157
$this->commentsManager->expects($this->once())
5258
->method('get')
5359
->with('55')
54-
->willReturn(
55-
$this->getMockBuilder(IComment::class)
56-
->disableOriginalConstructor()
57-
->getMock()
58-
);
60+
->willReturn($comment);
5961

6062
$node = $this->collection->getChild('55');
6163
$this->assertInstanceOf(CommentNode::class, $node);
@@ -107,6 +109,17 @@ public function testFindChildren(): void {
107109
}
108110

109111
public function testChildExistsTrue(): void {
112+
$comment = $this->createMock(IComment::class);
113+
$comment->method('getObjectType')
114+
->willReturn('files');
115+
$comment->method('getObjectId')
116+
->willReturn('19');
117+
118+
$this->commentsManager->expects($this->once())
119+
->method('get')
120+
->with('44')
121+
->willReturn($comment);
122+
110123
$this->assertTrue($this->collection->childExists('44'));
111124
}
112125

lib/private/DB/QueryBuilder/QueryBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,10 @@ public function orHaving(...$having) {
10941094
* @return $this This QueryBuilder instance.
10951095
*/
10961096
public function orderBy($sort, $order = null) {
1097+
if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) {
1098+
$order = null;
1099+
}
1100+
10971101
$this->queryBuilder->orderBy(
10981102
$this->helper->quoteColumnName($sort),
10991103
$order
@@ -1111,6 +1115,10 @@ public function orderBy($sort, $order = null) {
11111115
* @return $this This QueryBuilder instance.
11121116
*/
11131117
public function addOrderBy($sort, $order = null) {
1118+
if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) {
1119+
$order = null;
1120+
}
1121+
11141122
$this->queryBuilder->addOrderBy(
11151123
$this->helper->quoteColumnName($sort),
11161124
$order

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

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

282282
public function addOrderBy($sort, $order = null) {
283-
$this->registerOrder((string)$sort, (string)$order ?? 'ASC');
283+
if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) {
284+
$order = null;
285+
}
286+
287+
$this->registerOrder((string)$sort, (string)($order ?? 'ASC'));
284288
return parent::addOrderBy($sort, $order);
285289
}
286290

287291
public function orderBy($sort, $order = null) {
292+
if ($order !== null && !in_array(strtoupper((string)$order), ['ASC', 'DESC'], true)) {
293+
$order = null;
294+
}
295+
288296
$this->sortList = [];
289-
$this->registerOrder((string)$sort, (string)$order ?? 'ASC');
297+
$this->registerOrder((string)$sort, (string)($order ?? 'ASC'));
290298
return parent::orderBy($sort, $order);
291299
}
292300

0 commit comments

Comments
 (0)