From d7d4b03aa03a9c3345ecdb9c31712c7ee225ab6d Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 3 Jul 2024 14:37:29 +0200 Subject: [PATCH 1/2] Limit contact.username to 254 chars --- .../Notifications/Web/Form/ContactForm.php | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/library/Notifications/Web/Form/ContactForm.php b/library/Notifications/Web/Form/ContactForm.php index bd2037fd..023edd3d 100644 --- a/library/Notifications/Web/Form/ContactForm.php +++ b/library/Notifications/Web/Form/ContactForm.php @@ -16,6 +16,7 @@ use ipl\Stdlib\Filter; use ipl\Validator\CallbackValidator; use ipl\Validator\EmailAddressValidator; +use ipl\Validator\StringLengthValidator; use ipl\Web\Common\CsrfCounterMeasure; use ipl\Web\Compat\CompatForm; @@ -95,20 +96,25 @@ protected function assemble() 'username', [ 'label' => $this->translate('Username'), - 'validators' => [new CallbackValidator(function ($value, $validator) { - $contact = Contact::on($this->db)->filter(Filter::equal('username', $value)); - if ($this->contactId) { - $contact->filter(Filter::unequal('id', $this->contactId)); - } - - if ($contact->first() !== null) { - $validator->addMessage($this->translate('A contact with the same username already exists.')); - - return false; - } - - return true; - })] + 'validators' => [ + new StringLengthValidator(['max' => 254]), + new CallbackValidator(function ($value, $validator) { + $contact = Contact::on($this->db)->filter(Filter::equal('username', $value)); + if ($this->contactId) { + $contact->filter(Filter::unequal('id', $this->contactId)); + } + + if ($contact->first() !== null) { + $validator->addMessage($this->translate( + 'A contact with the same username already exists.' + )); + + return false; + } + + return true; + }) + ] ] )->addElement( 'select', From a9c8384b95785c2e3b400524eee30f1d54b0eafe Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 3 Jul 2024 14:42:55 +0200 Subject: [PATCH 2/2] Limit contact.contact_address to 255 chars --- library/Notifications/Web/Form/ContactForm.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/Notifications/Web/Form/ContactForm.php b/library/Notifications/Web/Form/ContactForm.php index 023edd3d..17121f95 100644 --- a/library/Notifications/Web/Form/ContactForm.php +++ b/library/Notifications/Web/Form/ContactForm.php @@ -289,7 +289,11 @@ private function addAddressElements(): void $this->addElement($address); foreach ($plugins as $type => $label) { - $element = $this->createElement('text', $type, ['label' => $label]); + $element = $this->createElement('text', $type, [ + 'label' => $label, + 'validators' => [new StringLengthValidator(['max' => 255])] + ]); + if ($type === 'email') { $element->addAttributes(['validators' => [new EmailAddressValidator()]]); }