From 2aae231710a0cf78b779ed50a8cc9e8b731aa975 Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Thu, 3 Oct 2024 23:15:52 -0600 Subject: [PATCH] EbookTag validation: Trim name and check for empty string --- lib/EbookTag.php | 5 +++++ lib/Exceptions/EbookTagNameRequiredException.php | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 lib/Exceptions/EbookTagNameRequiredException.php diff --git a/lib/EbookTag.php b/lib/EbookTag.php index 34758d8d..69c214ed 100644 --- a/lib/EbookTag.php +++ b/lib/EbookTag.php @@ -33,6 +33,11 @@ class EbookTag extends Tag{ public function Validate(): void{ $error = new Exceptions\ValidationException(); + $this->Name = trim($this->Name ?? ''); + if($this->Name == ''){ + $error->Add(new Exceptions\EbookTagNameRequiredException()); + } + if(strlen($this->Name) > EBOOKS_MAX_STRING_LENGTH){ $error->Add(new Exceptions\StringTooLongException('Ebook tag: '. $this->Name)); } diff --git a/lib/Exceptions/EbookTagNameRequiredException.php b/lib/Exceptions/EbookTagNameRequiredException.php new file mode 100644 index 00000000..6ab74a8a --- /dev/null +++ b/lib/Exceptions/EbookTagNameRequiredException.php @@ -0,0 +1,7 @@ +