Skip to content

Commit e713d0b

Browse files
Merge pull request #56996 from nextcloud/backport/56982/stable21
[stable21] fix(comments): Check comment object
2 parents 11a19ad + 7b274fa commit e713d0b

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
@@ -102,6 +102,10 @@ public function getId() {
102102
public function getChild($name) {
103103
try {
104104
$comment = $this->commentsManager->get($name);
105+
if ($comment->getObjectType() !== $this->name
106+
|| $comment->getObjectId() !== $this->id) {
107+
throw new NotFound();
108+
}
105109
return new CommentNode(
106110
$this->commentsManager,
107111
$comment,
@@ -155,8 +159,9 @@ public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null
155159
*/
156160
public function childExists($name) {
157161
try {
158-
$this->commentsManager->get($name);
159-
return true;
162+
$comment = $this->commentsManager->get($name);
163+
return $comment->getObjectType() === $this->name
164+
&& $comment->getObjectId() === $this->id;
160165
} catch (NotFoundException $e) {
161166
return false;
162167
}

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

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

7979
public function testGetChild() {
80+
$comment = $this->createMock(IComment::class);
81+
$comment->method('getObjectType')
82+
->willReturn('files');
83+
$comment->method('getObjectId')
84+
->willReturn('19');
85+
8086
$this->commentsManager->expects($this->once())
8187
->method('get')
8288
->with('55')
83-
->willReturn(
84-
$this->getMockBuilder(IComment::class)
85-
->disableOriginalConstructor()
86-
->getMock()
87-
);
89+
->willReturn($comment);
8890

8991
$node = $this->collection->getChild('55');
9092
$this->assertTrue($node instanceof \OCA\DAV\Comments\CommentNode);
@@ -136,6 +138,17 @@ public function testFindChildren() {
136138
}
137139

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

lib/private/DB/QueryBuilder/QueryBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,10 @@ public function orHaving(...$having) {
10561056
* @return $this This QueryBuilder instance.
10571057
*/
10581058
public function orderBy($sort, $order = null) {
1059+
if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) {
1060+
$order = null;
1061+
}
1062+
10591063
$this->queryBuilder->orderBy(
10601064
$this->helper->quoteColumnName($sort),
10611065
$order
@@ -1073,6 +1077,10 @@ public function orderBy($sort, $order = null) {
10731077
* @return $this This QueryBuilder instance.
10741078
*/
10751079
public function addOrderBy($sort, $order = null) {
1080+
if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) {
1081+
$order = null;
1082+
}
1083+
10761084
$this->queryBuilder->addOrderBy(
10771085
$this->helper->quoteColumnName($sort),
10781086
$order

0 commit comments

Comments
 (0)