mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-24 19:20:12 +01:00
Fixed #1285 to support newer top level domain names (TLD) as well
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
81ffefbc65
commit
129f640421
@ -34,6 +34,8 @@ $config['TITLE_PREFIX'] = '';
|
|||||||
$config['CUSTOM_PRE_AUTH_FUNCTION'] = '';
|
$config['CUSTOM_PRE_AUTH_FUNCTION'] = '';
|
||||||
$config['CUSTOM_EMAIL_QUERY_FUNCTION'] = '';
|
$config['CUSTOM_EMAIL_QUERY_FUNCTION'] = '';
|
||||||
|
|
||||||
|
$config['DOMAIN_REGEX'] = '/^[a-zA-Z0-9]+[a-zA-Z0-9-_\.]{0,}\.[a-zA-Z0-9]{2,20}$/';
|
||||||
|
|
||||||
$config['BOOTSTRAP_THEME'] = '-cosmo';
|
$config['BOOTSTRAP_THEME'] = '-cosmo';
|
||||||
|
|
||||||
$config['DEFAULT_LANG'] = 'en';
|
$config['DEFAULT_LANG'] = 'en';
|
||||||
|
@ -145,13 +145,12 @@ function checkemail($email, $domains) {
|
|||||||
|
|
||||||
|
|
||||||
function validemail($email = '') {
|
function validemail($email = '') {
|
||||||
if($email == '') { return 0; }
|
if($email == '' || !strchr($email, '@')) { return 0; }
|
||||||
|
|
||||||
if(preg_match("/@local$/", $email)) { return 1; }
|
$arr = explode("@", $email);
|
||||||
|
|
||||||
if(preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,10})$/', $email)) {
|
// This is a pretty relaxed formula making sure we have something as the local part
|
||||||
return 1;
|
if(count($arr) == 2 && strlen($arr[0]) >= 1 && validdomain($arr[1])) { return 1; }
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -173,7 +172,7 @@ function checkdomain($domain, $domains) {
|
|||||||
|
|
||||||
|
|
||||||
function validdomain($domain = '') {
|
function validdomain($domain = '') {
|
||||||
if(preg_match("/@?local$/", $domain) || preg_match('/^[a-zA-Z0-9]+[a-zA-Z0-9-_\.]{0,}\.[a-zA-Z0-9]{2,10}$/', $domain)) {
|
if(preg_match("/@?local$/", $domain) || preg_match(DOMAIN_REGEX, $domain)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
45
webui/tests/MiscTest.php
Normal file
45
webui/tests/MiscTest.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
require_once dirname(dirname(__FILE__)) . '/config.php';
|
||||||
|
require_once dirname(dirname(__FILE__)) . '/system/model.php';
|
||||||
|
require_once dirname(dirname(__FILE__)) . '/system/loader.php';
|
||||||
|
require_once dirname(dirname(__FILE__)) . '/system/language.php';
|
||||||
|
require_once dirname(dirname(__FILE__)) . '/system/misc.php';
|
||||||
|
|
||||||
|
final class MiscTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function providerTestValiddomain() {
|
||||||
|
return [
|
||||||
|
['', 0],
|
||||||
|
['local', 1],
|
||||||
|
['@local', 1],
|
||||||
|
['aaa.fu', 1],
|
||||||
|
['@aaa.fu', 0],
|
||||||
|
['AAa.fu', 1],
|
||||||
|
['.aaa.fu', 0],
|
||||||
|
['-aaa.fu', 0],
|
||||||
|
['_aaa.fu', 0],
|
||||||
|
['2aaa.fu', 1],
|
||||||
|
['aaafu', 0],
|
||||||
|
['a.com.', 0],
|
||||||
|
['a.co.uk', 1],
|
||||||
|
['a.co.u2k', 1],
|
||||||
|
['a.com', 1],
|
||||||
|
['ccc.com', 1],
|
||||||
|
['aaa.bbb.ccc.com', 1],
|
||||||
|
['aaa.photography', 1],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestValiddomain
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function test_validdomain($data, $expected_result) {
|
||||||
|
$result = validdomain($data);
|
||||||
|
$this->assertEquals($result, $expected_result);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user