summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-01-22 15:17:29 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-01-22 16:23:50 +0100
commit3d42ecea37527216b70833577a1d1f5cd82151f6 (patch)
tree794e75a20421b7bd9c04fc4d2a8bffc7301b5dfe
parentb5b491d1bb12a869ddae7878e8aa441109419a00 (diff)
downloadnextcloud-server-3d42ecea37527216b70833577a1d1f5cd82151f6.tar.gz
nextcloud-server-3d42ecea37527216b70833577a1d1f5cd82151f6.zip
Fix undefined offset 1 for wrong user mail address
* fixes Undefined offset: 1 at lib/private/mail.php#143
-rw-r--r--lib/private/mail.php3
-rw-r--r--tests/lib/mail.php36
2 files changed, 27 insertions, 12 deletions
diff --git a/lib/private/mail.php b/lib/private/mail.php
index 8ba7343e011..6b7eec6e080 100644
--- a/lib/private/mail.php
+++ b/lib/private/mail.php
@@ -126,6 +126,9 @@ class OC_Mail {
* @return bool
*/
public static function validateAddress($emailAddress) {
+ if (strpos($emailAddress, '@') === false) {
+ return false;
+ }
$emailAddress = self::buildAsciiEmail($emailAddress);
return PHPMailer::ValidateAddress($emailAddress);
}
diff --git a/tests/lib/mail.php b/tests/lib/mail.php
index 568ecff52b0..813dde1944f 100644
--- a/tests/lib/mail.php
+++ b/tests/lib/mail.php
@@ -8,28 +8,23 @@
class Test_Mail extends \Test\TestCase {
- protected function setUp()
- {
- parent::setUp();
-
- if (!function_exists('idn_to_ascii')) {
- $this->markTestSkipped(
- 'The intl extension is not available.'
- );
- }
- }
-
/**
* @dataProvider buildAsciiEmailProvider
* @param $expected
* @param $address
*/
public function testBuildAsciiEmail($expected, $address) {
+ if (!function_exists('idn_to_ascii')) {
+ $this->markTestSkipped(
+ 'The intl extension is not available.'
+ );
+ }
+
$actual = \OC_Mail::buildAsciiEmail($address);
$this->assertEquals($expected, $actual);
}
- function buildAsciiEmailProvider() {
+ public function buildAsciiEmailProvider() {
return array(
array('info@example.com', 'info@example.com'),
array('info@xn--cjr6vy5ejyai80u.com', 'info@國際化域名.com'),
@@ -38,4 +33,21 @@ class Test_Mail extends \Test\TestCase {
);
}
+ public function validateMailProvider() {
+ return array(
+ array('infoatexample.com', false),
+ array('info', false),
+ );
+ }
+
+ /**
+ * @dataProvider validateMailProvider
+ * @param $address
+ * @param $expected
+ */
+ public function testValidateEmail($address, $expected) {
+ $actual = \OC_Mail::validateAddress($address);
+ $this->assertEquals($expected, $actual);
+ }
+
}