Skip to content

Commit 979cc87

Browse files
Merge pull request #47662 from nextcloud/fix/notification/validate-rich-object-key-value-types
2 parents a7eaed7 + a3da745 commit 979cc87

File tree

7 files changed

+43
-10
lines changed

7 files changed

+43
-10
lines changed

apps/files_sharing/lib/Notification/Notifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ protected function parseShareExpiration(IShare $share, INotification $notificati
126126
[
127127
'node' => [
128128
'type' => 'file',
129-
'id' => $node->getId(),
129+
'id' => (string)$node->getId(),
130130
'name' => $node->getName(),
131-
'path' => $path,
131+
'path' => (string)$path,
132132
],
133133
]
134134
);

lib/private/Activity/Event.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function getRichSubject(): string {
259259
}
260260

261261
/**
262-
* @return array[]
262+
* @return array<string, array<string, string>>
263263
* @since 11.0.0
264264
*/
265265
public function getRichSubjectParameters(): array {
@@ -335,7 +335,7 @@ public function getRichMessage(): string {
335335
}
336336

337337
/**
338-
* @return array[]
338+
* @return array<string, array<string, string>>
339339
* @since 11.0.0
340340
*/
341341
public function getRichMessageParameters(): array {

lib/private/RichObjectStrings/Validator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ protected function validateParameter(array $parameter) {
7878
if (!empty($missingKeys)) {
7979
throw new InvalidObjectExeption('Object is invalid, missing keys:'.json_encode($missingKeys));
8080
}
81+
82+
foreach ($parameter as $key => $value) {
83+
if (!is_string($key)) {
84+
throw new InvalidObjectExeption('Object is invalid, key ' . $key . ' is not a string');
85+
}
86+
if (!is_string($value)) {
87+
throw new InvalidObjectExeption('Object is invalid, value ' . $value . ' is not a string');
88+
}
89+
}
8190
}
8291

8392
/**

lib/public/Activity/IEvent.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function getParsedSubject(): string;
121121
* See https://github.com/nextcloud/server/issues/1706 for more information.
122122
*
123123
* @param string $subject
124-
* @param array $parameters
124+
* @param array<string, array<string, string>> $parameters
125125
* @return $this
126126
* @throws InvalidValueException if the subject or parameters are invalid
127127
* @since 11.0.0
@@ -136,7 +136,7 @@ public function setRichSubject(string $subject, array $parameters = []): self;
136136
public function getRichSubject(): string;
137137

138138
/**
139-
* @return array[]
139+
* @return array<string, array<string, string>>
140140
* @since 11.0.0
141141
*/
142142
public function getRichSubjectParameters(): array;
@@ -187,7 +187,7 @@ public function getParsedMessage(): string;
187187
* See https://github.com/nextcloud/server/issues/1706 for more information.
188188
*
189189
* @param string $message
190-
* @param array $parameters
190+
* @param array<string, array<string, string>> $parameters
191191
* @return $this
192192
* @throws \InvalidArgumentException if the message or parameters are invalid
193193
* @since 11.0.0
@@ -202,7 +202,7 @@ public function setRichMessage(string $message, array $parameters = []): self;
202202
public function getRichMessage(): string;
203203

204204
/**
205-
* @return array[]
205+
* @return array<string, array<string, string>>
206206
* @since 11.0.0
207207
*/
208208
public function getRichMessageParameters(): array;

lib/public/Notification/INotification.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function getParsedSubject(): string;
137137
* See https://github.com/nextcloud/server/issues/1706 for more information.
138138
*
139139
* @param string $subject
140-
* @param array $parameters
140+
* @param array<string, array<string, string>> $parameters
141141
* @return $this
142142
* @throws InvalidValueException if the subject or parameters are invalid
143143
* @since 11.0.0
@@ -213,7 +213,7 @@ public function getParsedMessage(): string;
213213
* See https://github.com/nextcloud/server/issues/1706 for more information.
214214
*
215215
* @param string $message
216-
* @param array $parameters
216+
* @param array<string, array<string, string>> $parameters
217217
* @return $this
218218
* @throws InvalidValueException if the message or parameters are invalid
219219
* @since 11.0.0

lib/public/SetupCheck/SetupResult.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class SetupResult implements \JsonSerializable {
4545
/**
4646
* @brief Private constructor, use success()/info()/warning()/error() instead
4747
* @param self::SUCCESS|self::INFO|self::WARNING|self::ERROR $severity
48+
* @param array<string, array<string, string>> $descriptionParameters
4849
* @throws \OCP\RichObjectStrings\InvalidObjectExeption
4950
* @since 28.0.0
5051
* @since 28.0.2 Optional parameter ?array $descriptionParameters

tests/lib/RichObjectStrings/ValidatorTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use OC\RichObjectStrings\Validator;
1010
use OCP\RichObjectStrings\Definitions;
11+
use OCP\RichObjectStrings\InvalidObjectExeption;
1112
use Test\TestCase;
1213

1314
class ValidatorTest extends TestCase {
@@ -33,5 +34,27 @@ public function test() {
3334
],
3435
]);
3536
$this->addToAssertionCount(2);
37+
38+
$this->expectException(InvalidObjectExeption::class);
39+
40+
$this->expectExceptionMessage('Object is invalid, value 123 is not a string');
41+
$v->validate('test {string1} test.', [
42+
'string1' => [
43+
'type' => 'user',
44+
'id' => 'johndoe',
45+
'name' => 'John Doe',
46+
'key' => 123,
47+
],
48+
]);
49+
50+
$this->expectExceptionMessage('Object is invalid, key 456 is not a string');
51+
$v->validate('test {string1} test.', [
52+
'string1' => [
53+
'type' => 'user',
54+
'id' => 'johndoe',
55+
'name' => 'John Doe',
56+
456 => 'value',
57+
],
58+
]);
3659
}
3760
}

0 commit comments

Comments
 (0)