diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-11-21 15:57:09 +0100 |
---|---|---|
committer | Côme Chilliet (Rebase PR Action) <come-nc@users.noreply.github.com> | 2022-11-29 14:36:29 +0000 |
commit | 8a04bf5584e93b67d88bbc2293e0455ae8a7be1e (patch) | |
tree | b0769deed616b756401277635fd89f05b6c27e3a /lib/private/Notification | |
parent | cf8d97c9d31fc487f9347c120145ab4d70b4d0ee (diff) | |
download | nextcloud-server-8a04bf5584e93b67d88bbc2293e0455ae8a7be1e.tar.gz nextcloud-server-8a04bf5584e93b67d88bbc2293e0455ae8a7be1e.zip |
Apply the same changes to richToParsed in Notification
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/Notification')
-rw-r--r-- | lib/private/Notification/Notification.php | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php index 9610a2d2a12..1ced034d7c6 100644 --- a/lib/private/Notification/Notification.php +++ b/lib/private/Notification/Notification.php @@ -302,17 +302,23 @@ class Notification implements INotification { 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); |