diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-12-08 17:17:58 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-12-08 17:17:58 +0100 |
commit | f676076482433da01ce7d60ea68f04fa84a33f86 (patch) | |
tree | 9c5eb988502f50d1796c9c4a36dca0f7c8a8edbe /lib/private/Activity/Event.php | |
parent | 8a04bf5584e93b67d88bbc2293e0455ae8a7be1e (diff) | |
download | nextcloud-server-f676076482433da01ce7d60ea68f04fa84a33f86.tar.gz nextcloud-server-f676076482433da01ce7d60ea68f04fa84a33f86.zip |
Throw on missing type of rich subject parameter
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/Activity/Event.php')
-rw-r--r-- | lib/private/Activity/Event.php | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/private/Activity/Event.php b/lib/private/Activity/Event.php index 806a7514590..cc1135cf179 100644 --- a/lib/private/Activity/Event.php +++ b/lib/private/Activity/Event.php @@ -276,19 +276,21 @@ class Event implements IEvent { } /** - * @throws \InvalidArgumentException if a parameter has no name + * @throws \InvalidArgumentException if a parameter has no name or no type */ private function richToParsed(string $message, array $parameters): string { $placeholders = []; $replacements = []; foreach ($parameters as $placeholder => $parameter) { $placeholders[] = '{' . $placeholder . '}'; - if (!isset($parameter['name']) || !is_string($parameter['name'])) { - throw new \InvalidArgumentException('Invalid rich object, name field is missing'); + foreach (['name','type'] as $requiredField) { + if (!isset($parameter[$requiredField]) || !is_string($parameter[$requiredField])) { + throw new \InvalidArgumentException("Invalid rich object, {$requiredField} field is missing"); + } } - if (($parameter['type'] ?? '') === 'user') { + if ($parameter['type'] === 'user') { $replacements[] = '@' . $parameter['name']; - } elseif (($parameter['type'] ?? '') === 'file') { + } elseif ($parameter['type'] === 'file') { $replacements[] = $parameter['path'] ?? $parameter['name']; } else { $replacements[] = $parameter['name']; |