Skip to content

Commit c996325

Browse files
committed
fix(comments): Check comment object
Signed-off-by: Joas Schilling <[email protected]>
1 parent 40cfffb commit c996325

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

apps/dav/lib/Comments/EntityCollection.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public function getId() {
100100
public function getChild($name) {
101101
try {
102102
$comment = $this->commentsManager->get($name);
103+
if ($comment->getObjectType() !== $this->name
104+
|| $comment->getObjectId() !== $this->id) {
105+
throw new NotFound();
106+
}
103107
return new CommentNode(
104108
$this->commentsManager,
105109
$comment,
@@ -153,8 +157,9 @@ public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null
153157
*/
154158
public function childExists($name) {
155159
try {
156-
$this->commentsManager->get($name);
157-
return true;
160+
$comment = $this->commentsManager->get($name);
161+
return $comment->getObjectType() === $this->name
162+
&& $comment->getObjectId() === $this->id;
158163
} catch (NotFoundException $e) {
159164
return false;
160165
}

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

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

7878
public function testGetChild(): void {
79+
$comment = $this->createMock(IComment::class);
80+
$comment->method('getObjectType')
81+
->willReturn('files');
82+
$comment->method('getObjectId')
83+
->willReturn('19');
84+
7985
$this->commentsManager->expects($this->once())
8086
->method('get')
8187
->with('55')
82-
->willReturn(
83-
$this->getMockBuilder(IComment::class)
84-
->disableOriginalConstructor()
85-
->getMock()
86-
);
88+
->willReturn($comment);
8789

8890
$node = $this->collection->getChild('55');
8991
$this->assertTrue($node instanceof \OCA\DAV\Comments\CommentNode);
@@ -135,6 +137,17 @@ public function testFindChildren(): void {
135137
}
136138

137139
public function testChildExistsTrue(): void {
140+
$comment = $this->createMock(IComment::class);
141+
$comment->method('getObjectType')
142+
->willReturn('files');
143+
$comment->method('getObjectId')
144+
->willReturn('19');
145+
146+
$this->commentsManager->expects($this->once())
147+
->method('get')
148+
->with('44')
149+
->willReturn($comment);
150+
138151
$this->assertTrue($this->collection->childExists('44'));
139152
}
140153

lib/private/DB/QueryBuilder/QueryBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,10 @@ public function orHaving(...$having) {
11071107
* @return $this This QueryBuilder instance.
11081108
*/
11091109
public function orderBy($sort, $order = null) {
1110+
if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) {
1111+
$order = null;
1112+
}
1113+
11101114
$this->queryBuilder->orderBy(
11111115
$this->helper->quoteColumnName($sort),
11121116
$order
@@ -1124,6 +1128,10 @@ public function orderBy($sort, $order = null) {
11241128
* @return $this This QueryBuilder instance.
11251129
*/
11261130
public function addOrderBy($sort, $order = null) {
1131+
if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) {
1132+
$order = null;
1133+
}
1134+
11271135
$this->queryBuilder->addOrderBy(
11281136
$this->helper->quoteColumnName($sort),
11291137
$order

0 commit comments

Comments
 (0)