mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Throw on missing type of rich subject parameter
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
8a04bf5584
commit
f676076482
2 changed files with 14 additions and 10 deletions
|
|
@ -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'];
|
||||
|
|
|
|||
|
|
@ -303,19 +303,21 @@ class Notification implements INotification {
|
|||
}
|
||||
|
||||
/**
|
||||
* @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'];
|
||||
|
|
|
|||
Loading…
Reference in a new issue