Skip to content

Commit 3aa72a0

Browse files
Merge pull request #56992 from nextcloud/backport/56982/stable25
[stable25] fix(comments): Check comment object
2 parents 060fb4c + 1454faf commit 3aa72a0

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() {
7676
}
7777

7878
public function testGetChild() {
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() {
135137
}
136138

137139
public function testChildExistsTrue() {
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
@@ -1102,6 +1102,10 @@ public function orHaving(...$having) {
11021102
* @return $this This QueryBuilder instance.
11031103
*/
11041104
public function orderBy($sort, $order = null) {
1105+
if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) {
1106+
$order = null;
1107+
}
1108+
11051109
$this->queryBuilder->orderBy(
11061110
$this->helper->quoteColumnName($sort),
11071111
$order
@@ -1119,6 +1123,10 @@ public function orderBy($sort, $order = null) {
11191123
* @return $this This QueryBuilder instance.
11201124
*/
11211125
public function addOrderBy($sort, $order = null) {
1126+
if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) {
1127+
$order = null;
1128+
}
1129+
11221130
$this->queryBuilder->addOrderBy(
11231131
$this->helper->quoteColumnName($sort),
11241132
$order

0 commit comments

Comments
 (0)