From 8a04bf5584e93b67d88bbc2293e0455ae8a7be1e Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Mon, 21 Nov 2022 15:57:09 +0100 Subject: Apply the same changes to richToParsed in Notification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Notification/Notification.php | 12 +++++++++--- 1 file 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); -- cgit v1.2.3