]> source.dussan.org Git - nextcloud-server.git/commitdiff
Micro-optimize validation of empty email addresses 25585/head
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Thu, 11 Feb 2021 14:15:38 +0000 (15:15 +0100)
committerChristoph Wurst <christoph@winzerhof-wurst.at>
Thu, 11 Feb 2021 14:15:38 +0000 (15:15 +0100)
Then we don't have to construct any validators.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
lib/private/Mail/Mailer.php
tests/lib/Mail/MailerTest.php

index f8dc739428a450ff5ca06d7487bdf0fc234f96b9..2e996dea5025ca9939e9deb405718936f6e5bbf2 100644 (file)
@@ -221,6 +221,10 @@ class Mailer implements IMailer {
         * @return bool True if the mail address is valid, false otherwise
         */
        public function validateMailAddress(string $email): bool {
+               if ($email === '') {
+                       // Shortcut: empty addresses are never valid
+                       return false;
+               }
                $validator = new EmailValidator();
                $validation = new RFCValidation();
 
index 3ec2e96dfab6239c4545713801669875c3abf945..a11a1ab091498ca0b220a8d2457e725af20a9384 100644 (file)
@@ -178,6 +178,7 @@ class MailerTest extends TestCase {
                        ['lukas@192.168.1.1', true],
                        ['lukas@éxämplè.com', true],
                        ['asdf', false],
+                       ['', false],
                        ['lukas@owncloud.org@owncloud.com', false],
                ];
        }