diff options
author | Marcel Klehr <mklehr@gmx.net> | 2024-07-09 12:43:31 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2024-07-17 13:55:55 +0200 |
commit | 5c457c64e88c4c7140c25a580c0964463b7c1094 (patch) | |
tree | 0d492ea5701f3ee54cd936088f3548f9ad4ec216 /lib/public | |
parent | 4ac1ac673e99ef067406b543c24d4c1e903238a4 (diff) | |
download | nextcloud-server-5c457c64e88c4c7140c25a580c0964463b7c1094.tar.gz nextcloud-server-5c457c64e88c4c7140c25a580c0964463b7c1094.zip |
fix: Validate output properly
Differentiate between output with file IDs and output with File data
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/TaskProcessing/EShapeType.php | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/public/TaskProcessing/EShapeType.php b/lib/public/TaskProcessing/EShapeType.php index d66de6e01a8..ade78fda71a 100644 --- a/lib/public/TaskProcessing/EShapeType.php +++ b/lib/public/TaskProcessing/EShapeType.php @@ -89,7 +89,7 @@ enum EShapeType: int { * @throws ValidationException * @since 30.0.0 */ - public function validateOutput(mixed $value) { + public function validateOutputWithFileData(mixed $value): void { $this->validateNonFileType($value); if ($this === EShapeType::Image && !is_string($value)) { throw new ValidationException('Non-image item provided for Image slot'); @@ -118,6 +118,39 @@ enum EShapeType: int { } /** + * @param mixed $value + * @return void + * @throws ValidationException + */ + public function validateOutputWithFileIds(mixed $value): void { + $this->validateNonFileType($value); + if ($this === EShapeType::Image && !is_numeric($value)) { + throw new ValidationException('Non-image item provided for Image slot'); + } + if ($this === EShapeType::ListOfImages && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { + throw new ValidationException('Non-image list item provided for ListOfImages slot'); + } + if ($this === EShapeType::Audio && !is_string($value)) { + throw new ValidationException('Non-audio item provided for Audio slot'); + } + if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { + throw new ValidationException('Non-audio list item provided for ListOfAudio slot'); + } + if ($this === EShapeType::Video && !is_string($value)) { + throw new ValidationException('Non-video item provided for Video slot'); + } + if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { + throw new ValidationException('Non-video list item provided for ListOfTexts slot'); + } + if ($this === EShapeType::File && !is_string($value)) { + throw new ValidationException('Non-file item provided for File slot'); + } + if ($this === EShapeType::ListOfFiles && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { + throw new ValidationException('Non-audio list item provided for ListOfFiles slot'); + } + } + + /** * @param EShapeType $type * @return EShapeType * @since 30.0.0 |