mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-04 09:08:52 +00:00
[ticket/9066] Move regex into get_preg_expression function and add tests
PHPBB3-9066
This commit is contained in:
parent
6370ef2705
commit
3302305cd4
3 changed files with 40 additions and 1 deletions
|
@ -3486,6 +3486,10 @@ function get_preg_expression($mode)
|
||||||
$inline = ($mode == 'relative_url') ? ')' : '';
|
$inline = ($mode == 'relative_url') ? ')' : '';
|
||||||
return "(?:[a-z0-9\-._~!$&'($inline*+,;=:@|]+|%[\dA-F]{2})*(?:/(?:[a-z0-9\-._~!$&'($inline*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~!$&'($inline*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-z0-9\-._~!$&'($inline*+,;=:@/?|]+|%[\dA-F]{2})*)?";
|
return "(?:[a-z0-9\-._~!$&'($inline*+,;=:@|]+|%[\dA-F]{2})*(?:/(?:[a-z0-9\-._~!$&'($inline*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~!$&'($inline*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-z0-9\-._~!$&'($inline*+,;=:@/?|]+|%[\dA-F]{2})*)?";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'table_prefix':
|
||||||
|
return '#^[a-zA-Z][a-zA-Z0-9_]*$#';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
|
|
@ -546,7 +546,7 @@ class install_install extends module
|
||||||
$error[] = $lang['INST_ERR_NO_DB'];
|
$error[] = $lang['INST_ERR_NO_DB'];
|
||||||
$connect_test = false;
|
$connect_test = false;
|
||||||
}
|
}
|
||||||
else if (!preg_match('#^[a-zA-Z][a-zA-Z0-9_]*$#', $data['table_prefix'], $result))
|
else if (!preg_match(get_preg_expression('table_prefix'), $data['table_prefix']))
|
||||||
{
|
{
|
||||||
$error[] = $lang['INST_ERR_DB_INVALID_PREFIX'];
|
$error[] = $lang['INST_ERR_DB_INVALID_PREFIX'];
|
||||||
$connect_test = false;
|
$connect_test = false;
|
||||||
|
|
35
tests/regex/table_prefix_test.php
Normal file
35
tests/regex/table_prefix_test.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2011 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||||
|
|
||||||
|
class phpbb_regex_table_prefix_test extends phpbb_test_case
|
||||||
|
{
|
||||||
|
public function table_prefix_test_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('phpbb_', 1),
|
||||||
|
array('phpBB3', 1),
|
||||||
|
array('a', 1),
|
||||||
|
|
||||||
|
array('', 0),
|
||||||
|
array('_', 0),
|
||||||
|
array('a-', 0),
|
||||||
|
array("'", 0),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider table_prefix_test_data
|
||||||
|
*/
|
||||||
|
public function test_table_prefix($prefix, $expected)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expected, preg_match(get_preg_expression('table_prefix'), $prefix));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue