mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-57531 mail: Make validate_email return actual boolean as expected
It was discovered by unit tests that the return value is not a real boolean as was intuitively expected and documented. To avoid potential issues with the truthyness in the future, we explicitly cast the return value to boolean now.
This commit is contained in:
parent
61367eb639
commit
7620746f67
@ -3442,10 +3442,10 @@ class core_moodlelib_testcase extends advanced_testcase {
|
||||
|
||||
$CFG->maildomain = 'example.com';
|
||||
$CFG->mailprefix = 'mdl+';
|
||||
$this->assertEquals(1, validate_email(generate_email_processing_address(0, $modargs)));
|
||||
$this->assertTrue(validate_email(generate_email_processing_address(0, $modargs)));
|
||||
|
||||
$CFG->maildomain = 'mail.example.com';
|
||||
$CFG->mailprefix = 'mdl-';
|
||||
$this->assertEquals(1, validate_email(generate_email_processing_address(23, $modargs)));
|
||||
$this->assertTrue(validate_email(generate_email_processing_address(23, $modargs)));
|
||||
}
|
||||
}
|
||||
|
@ -670,14 +670,14 @@ EXPECTED;
|
||||
*/
|
||||
public function test_validate_email() {
|
||||
|
||||
$this->assertEquals(1, validate_email('moodle@example.com'));
|
||||
$this->assertEquals(1, validate_email('moodle@localhost.local'));
|
||||
$this->assertEquals(1, validate_email('verp_email+is=mighty@moodle.org'));
|
||||
$this->assertEquals(1, validate_email("but_potentially'dangerous'too@example.org"));
|
||||
$this->assertEquals(1, validate_email('posts+AAAAAAAAAAIAAAAAAAAGQQAAAAABFSXz1eM/P/lR2bYyljM+@posts.moodle.org'));
|
||||
$this->assertTrue(validate_email('moodle@example.com'));
|
||||
$this->assertTrue(validate_email('moodle@localhost.local'));
|
||||
$this->assertTrue(validate_email('verp_email+is=mighty@moodle.org'));
|
||||
$this->assertTrue(validate_email("but_potentially'dangerous'too@example.org"));
|
||||
$this->assertTrue(validate_email('posts+AAAAAAAAAAIAAAAAAAAGQQAAAAABFSXz1eM/P/lR2bYyljM+@posts.moodle.org'));
|
||||
|
||||
$this->assertEquals(0, validate_email('moodle@localhost'));
|
||||
$this->assertEquals(0, validate_email('"attacker\\" -oQ/tmp/ -X/var/www/vhost/moodle/backdoor.php some"@email.com'));
|
||||
$this->assertEquals(0, validate_email("moodle@example.com>\r\nRCPT TO:<victim@example.com"));
|
||||
$this->assertFalse(validate_email('moodle@localhost'));
|
||||
$this->assertFalse(validate_email('"attacker\\" -oQ/tmp/ -X/var/www/vhost/moodle/backdoor.php some"@email.com'));
|
||||
$this->assertFalse(validate_email("moodle@example.com>\r\nRCPT TO:<victim@example.com"));
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ This files describes API changes in core libraries and APIs,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.3 ===
|
||||
|
||||
* YUI module moodle-core-formautosubmit has been removed, use jquery .change() instead (see lib/templates/url_select.mustache for
|
||||
an example)
|
||||
* Return value of the validate_email() is now proper boolean as documented. Previously the function could return 1, 0 or false.
|
||||
|
||||
=== 3.2 ===
|
||||
|
||||
|
@ -1088,12 +1088,12 @@ function page_get_doc_link_path(moodle_page $page) {
|
||||
*/
|
||||
function validate_email($address) {
|
||||
|
||||
return (preg_match('#^[-!\#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+'.
|
||||
return (bool)preg_match('#^[-!\#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+'.
|
||||
'(\.[-!\#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+)*'.
|
||||
'@'.
|
||||
'[-!\#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
|
||||
'[-!\#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$#',
|
||||
$address));
|
||||
$address);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user