diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-11-21 15:36:10 +0100 |
---|---|---|
committer | Côme Chilliet (Rebase PR Action) <come-nc@users.noreply.github.com> | 2022-11-29 14:36:29 +0000 |
commit | 2a3090d85c51d31b64439e64b433520724984618 (patch) | |
tree | 908d1d32c90abec19dcb829a4379704d761f5e8d /lib/private/Activity/Event.php | |
parent | d9151ff35c4280b8e5bbb92e33fe2b89c2bee458 (diff) | |
download | nextcloud-server-2a3090d85c51d31b64439e64b433520724984618.tar.gz nextcloud-server-2a3090d85c51d31b64439e64b433520724984618.zip |
Throw instead of using a bogus value if name field is missing
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, 9 insertions, 3 deletions
diff --git a/lib/private/Activity/Event.php b/lib/private/Activity/Event.php index b600a2c2249..806a7514590 100644 --- a/lib/private/Activity/Event.php +++ b/lib/private/Activity/Event.php @@ -275,17 +275,23 @@ class Event implements IEvent { return $this; } + /** + * @throws \InvalidArgumentException if a parameter has no name + */ 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'); + } if (($parameter['type'] ?? '') === 'user') { - $replacements[] = '@' . $parameter['name'] ?? 'invalid-user'; + $replacements[] = '@' . $parameter['name']; } elseif (($parameter['type'] ?? '') === 'file') { - $replacements[] = $parameter['path'] ?? $parameter['name'] ?? 'invalid-file'; + $replacements[] = $parameter['path'] ?? $parameter['name']; } else { - $replacements[] = $parameter['name'] ?? 'invalid-object'; + $replacements[] = $parameter['name']; } } return str_replace($placeholders, $replacements, $message); |