summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-02-11 15:15:38 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-02-11 15:15:38 +0100
commit883848b58a50b03702eab58f67ca577037fcedab (patch)
tree3c1a1c350b5f785db7c444604f95f4fb43fe96b2
parentd5dea10517bbceaf141f56b6dde0efb55fc6f4b5 (diff)
downloadnextcloud-server-883848b58a50b03702eab58f67ca577037fcedab.tar.gz
nextcloud-server-883848b58a50b03702eab58f67ca577037fcedab.zip
Micro-optimize validation of empty email addresses
Then we don't have to construct any validators. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r--lib/private/Mail/Mailer.php4
-rw-r--r--tests/lib/Mail/MailerTest.php1
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php
index f8dc739428a..2e996dea502 100644
--- a/lib/private/Mail/Mailer.php
+++ b/lib/private/Mail/Mailer.php
@@ -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();
diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php
index 3ec2e96dfab..a11a1ab0914 100644
--- a/tests/lib/Mail/MailerTest.php
+++ b/tests/lib/Mail/MailerTest.php
@@ -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],
];
}