From d94040bee51c4f1b1b08e0e5b55eccfda8778aef Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 19 Nov 2018 19:00:27 +0700 Subject: [PATCH] Fix multi empty string separated by "," marked as valid emails --- system/Validation/FormatRules.php | 8 +++++++- tests/system/Validation/FormatRulesTest.php | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/system/Validation/FormatRules.php b/system/Validation/FormatRules.php index e54c78a3c008..e0e527215bf9 100644 --- a/system/Validation/FormatRules.php +++ b/system/Validation/FormatRules.php @@ -294,7 +294,13 @@ public function valid_emails(string $str = null): bool foreach (explode(',', $str) as $email) { - if (trim($email) !== '' && $this->valid_email(trim($email)) === false) + $email = trim($email); + if ($email === '') + { + return false; + } + + if ($this->valid_email($email) === false) { return false; } diff --git a/tests/system/Validation/FormatRulesTest.php b/tests/system/Validation/FormatRulesTest.php index bd5c4c9dc149..4cba651aa8c0 100644 --- a/tests/system/Validation/FormatRulesTest.php +++ b/tests/system/Validation/FormatRulesTest.php @@ -241,6 +241,10 @@ public function emailsProvider() null, false, ], + [ + ',', + false, + ], ]; }